| author | |
| committer | |
| log | 73ac8ffff7b8bdc277711415eee9ede9d3a5e891 |
| tree | 9f5e9987bd7eb1f0ae586f32e36bfb3c72306e57 |
| parent | 8e5209615d55559b6c14005e762c234260c57af8 |
4 files changed, 36 insertions(+), 0 deletions(-)
build.zig+12| ... | @@ -22,4 +22,16 @@ pub fn build(b: *std.Build) void { | ... | @@ -22,4 +22,16 @@ pub fn build(b: *std.Build) void { |
| 22 | 22 | ||
| 23 | const run_step = b.step("run", "Run the app"); | 23 | const run_step = b.step("run", "Run the app"); |
| 24 | run_step.dependOn(&run_cmd.step); | 24 | run_step.dependOn(&run_cmd.step); |
| 25 | |||
| 26 | const tests = b.addTest(.{ | ||
| 27 | .root_source_file = b.path("test.zig"), | ||
| 28 | .target = target, | ||
| 29 | .optimize = mode, | ||
| 30 | }); | ||
| 31 | deps.addAllTo(tests); | ||
| 32 | |||
| 33 | const test_step = b.step("test", "Run all library tests"); | ||
| 34 | const tests_run = b.addRunArtifact(tests); | ||
| 35 | tests_run.has_side_effects = true; | ||
| 36 | test_step.dependOn(&tests_run.step); | ||
| 25 | } | 37 | } |
licenses.txt+1| ... | @@ -1,3 +1,4 @@ | ... | @@ -1,3 +1,4 @@ |
| 1 | MIT: | 1 | MIT: |
| 2 | = https://spdx.org/licenses/MIT | 2 | = https://spdx.org/licenses/MIT |
| 3 | - This | 3 | - This |
| 4 | - git https://github.com/nektro/zig-expect |
test.zig created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const leven = @import("leven").leven; | ||
| 3 | const expect = @import("expect").expect; | ||
| 4 | |||
| 5 | test { | ||
| 6 | const alloc = std.testing.allocator; | ||
| 7 | try expect(try leven(u8, alloc, "a", "b", 20)).toEqual(1); | ||
| 8 | try expect(try leven(u8, alloc, "ab", "ac", 20)).toEqual(1); | ||
| 9 | try expect(try leven(u8, alloc, "ac", "bc", 20)).toEqual(1); | ||
| 10 | try expect(try leven(u8, alloc, "abc", "axc", 20)).toEqual(1); | ||
| 11 | try expect(try leven(u8, alloc, "kitten", "sitting", 20)).toEqual(3); | ||
| 12 | try expect(try leven(u8, alloc, "xabxcdxxefxgx", "1ab2cd34ef5g6", 20)).toEqual(6); | ||
| 13 | try expect(try leven(u8, alloc, "cat", "cow", 20)).toEqual(2); | ||
| 14 | try expect(try leven(u8, alloc, "xabxcdxxefxgx", "abcdefg", 20)).toEqual(6); | ||
| 15 | try expect(try leven(u8, alloc, "javawasneat", "scalaisgreat", 20)).toEqual(7); | ||
| 16 | try expect(try leven(u8, alloc, "example", "samples", 20)).toEqual(3); | ||
| 17 | try expect(try leven(u8, alloc, "sturgeon", "urgently", 20)).toEqual(6); | ||
| 18 | try expect(try leven(u8, alloc, "levenshtein", "frankenstein", 20)).toEqual(6); | ||
| 19 | try expect(try leven(u8, alloc, "distance", "difference", 20)).toEqual(5); | ||
| 20 | // try expect(try leven(u8, alloc, "因為我是中國人所以我會說中文", "因為我是英國人所以我會說英文", 20)).toEqual(2); | ||
| 21 | } | ||
zig.mod+2| ... | @@ -3,3 +3,5 @@ name: leven | ... | @@ -3,3 +3,5 @@ name: leven |
| 3 | main: src/lib.zig | 3 | main: src/lib.zig |
| 4 | license: MIT | 4 | license: MIT |
| 5 | description: Measure the difference between two slices using the Levenshtein distance algorithm | 5 | description: Measure the difference between two slices using the Levenshtein distance algorithm |
| 6 | root_dependencies: | ||
| 7 | - src: git https://github.com/nektro/zig-expect |