From e8ac4fe5c401a8fe754a4a8533265027724c851c Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sat, 13 Feb 2021 20:51:34 +0900 Subject: [PATCH 01/39] GH-142: Migrate unit tests for Ref --- __test__/satysrc/generic.test.saty | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 __test__/satysrc/generic.test.saty diff --git a/__test__/satysrc/generic.test.saty b/__test__/satysrc/generic.test.saty new file mode 100644 index 0000000..9467f82 --- /dev/null +++ b/__test__/satysrc/generic.test.saty @@ -0,0 +1,32 @@ +@require: test/test +@require: test/expect + +@import: ../../src/ref + +open Test in +describe `Ref` [ + it `make 1 contains 1` (fun () -> ( + (Ref.make 1 |> Ref.get) == 1 + |> Expect.is-true + )); + it `set overrides the value of ref` (fun () -> ( + let r = Ref.make 1 in + let () = r |> Ref.set 2 in + (r |> Ref.get) == 2 + |> Expect.is-true + )); + it `swap two refs` (fun () -> ( + let r1 = Ref.make 1 in + let r2 = Ref.make 2 in + let () = Ref.swap r1 r2 in + (Ref.get r1 == 2) && (Ref.get r2 == 1) + |> Expect.is-true + )); + it `set temporarily value of ref` (fun () -> ( + let r = Ref.make 1 in + let r-tmp-value = r |> Ref.set-temporarily 2 (fun _ -> (Ref.get r)) in + let r-value = Ref.get r in + (r-tmp-value == 2) && (r-value == 1) + |> Expect.is-true + )) +] |> run From bbf142a34c11b9996c692727c6b19906a14f2621 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sun, 14 Feb 2021 07:19:50 +0900 Subject: [PATCH 02/39] GH-142: Migrate unit tests for String --- __test__/satysrc/generic.test.saty | 121 ++++++++++++++++++++++------- src/ord.satyg | 23 ++++++ 2 files changed, 118 insertions(+), 26 deletions(-) diff --git a/__test__/satysrc/generic.test.saty b/__test__/satysrc/generic.test.saty index 9467f82..6fb3037 100644 --- a/__test__/satysrc/generic.test.saty +++ b/__test__/satysrc/generic.test.saty @@ -1,32 +1,101 @@ @require: test/test @require: test/expect +@import: ../../src/eq +@import: ../../src/list-ext @import: ../../src/ref +@import: ../../src/string open Test in -describe `Ref` [ - it `make 1 contains 1` (fun () -> ( - (Ref.make 1 |> Ref.get) == 1 - |> Expect.is-true - )); - it `set overrides the value of ref` (fun () -> ( - let r = Ref.make 1 in - let () = r |> Ref.set 2 in - (r |> Ref.get) == 2 - |> Expect.is-true - )); - it `swap two refs` (fun () -> ( - let r1 = Ref.make 1 in - let r2 = Ref.make 2 in - let () = Ref.swap r1 r2 in - (Ref.get r1 == 2) && (Ref.get r2 == 1) - |> Expect.is-true - )); - it `set temporarily value of ref` (fun () -> ( - let r = Ref.make 1 in - let r-tmp-value = r |> Ref.set-temporarily 2 (fun _ -> (Ref.get r)) in - let r-value = Ref.get r in - (r-tmp-value == 2) && (r-value == 1) - |> Expect.is-true - )) -] |> run +describe `base` [ + describe `Ref module` [ + it `make 1 contains 1` (fun () -> ( + (Ref.make 1 |> Ref.get) == 1 + |> Expect.is-true + )); + it `set overrides the value of ref` (fun () -> ( + let r = Ref.make 1 in + let () = r |> Ref.set 2 in + (r |> Ref.get) == 2 + |> Expect.is-true + )); + it `swap two refs` (fun () -> ( + let r1 = Ref.make 1 in + let r2 = Ref.make 2 in + let () = Ref.swap r1 r2 in + (Ref.get r1 == 2) && (Ref.get r2 == 1) + |> Expect.is-true + )); + it `set temporarily value of ref` (fun () -> ( + let r = Ref.make 1 in + let r-tmp-value = r |> Ref.set-temporarily 2 (fun _ -> (Ref.get r)) in + let r-value = Ref.get r in + (r-tmp-value == 2) && (r-value == 1) + |> Expect.is-true + )) + ]; + describe `String module` [ + it `check equality of strings` (fun () -> ( + Eq.equal String.eq `abc` `abc` + && not Eq.equal String.eq `abc` `abd` + |> Expect.is-true + )); + it `concatenate strings` (fun () -> ( + String.concat [`a`; `b`; `c`] + |> string-same `abc` + |> Expect.is-true + )); + it `check emptiness of string` (fun () -> ( + String.is-empty ` ` + && (not String.is-empty `hi`) + |> Expect.is-true + )); + it `split string with a given delimiter` (fun () -> ( + let delimiter = Char.make `;` in + `spam;ham;eggs;` + |> String.split-by delimiter + |> Eq.equal (List.eq String.eq) [`spam`; `ham`; `eggs`; ` `] + |> Expect.is-true + )); + it `convert a string to a list of characters` (fun () -> ( + let expected = [ + Char.make `a`; + Char.make `b`; + Char.make `c`; + ] in + String.to-list `abc` + |> Eq.equal (List.eq Char.eq) expected + |> Expect.is-true + )); + it `compare strings with lexicographical order` (fun () -> ( + let subject = Ord.compare String.ord in + [ + subject `a` `a`; + subject `a` `b`; + subject `ab` `ba`; + subject `aab` `aba`; + subject `bbb` `bbba`; + ] |> Eq.equal (List.eq Ordering.eq) [ + Eq; Lt; Lt; Lt; Lt; + ] |> Expect.is-true + )); + % TODO + % * sub + % * of-bool + % * of-int + % * of-float + % * of-codepoints + % * of-char + % * of-length + % * append + % * starts-with + % * ends-with + % * of-list + % * pow + % * split + % * split-by-first + % * lines + % * index + ] +] +|> run diff --git a/src/ord.satyg b/src/ord.satyg index df00da5..e1db2cf 100644 --- a/src/ord.satyg +++ b/src/ord.satyg @@ -6,6 +6,29 @@ type ordering = Lt | Gt | Eq +module Ordering : sig + + val equal : ordering -> ordering -> bool + val eq : ordering Eq.t + +end = struct + + let equal a b = + match a with + | Lt -> (match b with + | Lt -> true + | _ -> false) + | Gt -> (match b with + | Gt -> true + | _ -> false) + | Eq -> (match b with + | Eq -> true + | _ -> false) + + let eq = Eq.make equal + +end + module Ord : sig type 'a t val make : ('a -> 'a -> ordering) -> 'a t From 63dd2d9ca929a85a758b5f972c98247a30faa0d3 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sun, 14 Feb 2021 07:27:51 +0900 Subject: [PATCH 03/39] GH-142: Move test files to test --- __test__/satysrc/generic.test.saty => test/main.test.saty | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename __test__/satysrc/generic.test.saty => test/main.test.saty (96%) diff --git a/__test__/satysrc/generic.test.saty b/test/main.test.saty similarity index 96% rename from __test__/satysrc/generic.test.saty rename to test/main.test.saty index 6fb3037..6f1b948 100644 --- a/__test__/satysrc/generic.test.saty +++ b/test/main.test.saty @@ -1,10 +1,10 @@ @require: test/test @require: test/expect -@import: ../../src/eq -@import: ../../src/list-ext -@import: ../../src/ref -@import: ../../src/string +@import: ../src/eq +@import: ../src/list-ext +@import: ../src/ref +@import: ../src/string open Test in describe `base` [ From 423a49c2f30ac3e642534a4423fede7d3b9db28f Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sun, 14 Feb 2021 07:42:12 +0900 Subject: [PATCH 04/39] GH-142: Add a dependency to satysfi-test --- Satyristes | 2 +- satysfi-base.opam | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Satyristes b/Satyristes index c239d6f..aa46857 100644 --- a/Satyristes +++ b/Satyristes @@ -6,4 +6,4 @@ ((packageDir "src") )) (opam "satysfi-base.opam") - (dependencies ((fonts-dejavu ())))) + (dependencies ((fonts-dejavu ()) (test ())))) diff --git a/satysfi-base.opam b/satysfi-base.opam index 369da74..c47eb2d 100644 --- a/satysfi-base.opam +++ b/satysfi-base.opam @@ -22,6 +22,7 @@ depends: [ "satysfi-dist" "satyrographos" {>= "0.0.2.6" & < "0.0.3"} "satysfi-fonts-dejavu" {>= "2.37"} + "satysfi-test" {>= "0.0.1" & < "0.0.2"} ] build: [ ] install: [ From e08eadb107bea5da0ea359c9b2e53f3e2e405e57 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sun, 14 Feb 2021 07:42:37 +0900 Subject: [PATCH 05/39] GH-142: Set up CI --- .github/workflows/ci.yml | 27 +++++++++++++++++++++++++++ test/run-test.sh | 23 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 test/run-test.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26224e7..5a58248 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,33 @@ name: CI on: [push, pull_request] jobs: + unit-test: + name: unit tests + runs-on: ubuntu-latest + container: + image: amutake/satysfi:opam-slim + steps: + - uses: actions/checkout@v1 + - name: Install Satyrographos dependencies + run: | + export HOME=/root + eval $(opam env) + opam update + opam pin add --verbose --yes "." + satyrographos install -l base + - name: Run tests + run: | + export HOME=/root + eval $(opam env) + cd test && sh run-test.sh -v + - if: always() + name: Install Apt dependencies + run: apt-get update && apt-get install -y xz-utils liblzma-dev + - name: Upload artifact + uses: actions/upload-artifact@master + with: + name: satysfi-test-report + path: test/report.txt regression-test: name: Regression tests runs-on: ubuntu-latest diff --git a/test/run-test.sh b/test/run-test.sh new file mode 100755 index 0000000..c7b4f4d --- /dev/null +++ b/test/run-test.sh @@ -0,0 +1,23 @@ +#! /bin/sh + +VERBOSE=0 +while getopts v OPT +do + case $OPT in + v) VERBOSE=1;; + esac +done + +rm -rf report.txt +if [ $VERBOSE -eq 1 ]; then + satysfi --text-mode "text" main.test.saty -o report.txt +else + satysfi --text-mode "text" main.test.saty -o report.txt > /dev/null +fi + +if [ -e report.txt ]; then + cat report.txt + cat report.txt | grep "0 fail" > /dev/null +else + exit 1 +fi From fd35f6034607e351a9824f299cec9997c527fd4f Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sun, 14 Feb 2021 08:26:18 +0900 Subject: [PATCH 06/39] GH-142: Ignore report.txt --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 966dd59..8420b3f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __test__/satysrc/*.pdf *.satysfi-aux node_modules *~ +report.txt From 28966cb6c27f7cbac1b94d654b4df0835d789380 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sun, 14 Feb 2021 08:26:47 +0900 Subject: [PATCH 07/39] GH-142: Split test cases into files based on modules --- test/main.test.saty | 94 +++--------------------------------------- test/ref.test.satyg | 32 ++++++++++++++ test/string.test.satyg | 74 +++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 89 deletions(-) create mode 100644 test/ref.test.satyg create mode 100644 test/string.test.satyg diff --git a/test/main.test.saty b/test/main.test.saty index 6f1b948..1becc57 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -6,96 +6,12 @@ @import: ../src/ref @import: ../src/string +@import: ref.test +@import: string.test + open Test in describe `base` [ - describe `Ref module` [ - it `make 1 contains 1` (fun () -> ( - (Ref.make 1 |> Ref.get) == 1 - |> Expect.is-true - )); - it `set overrides the value of ref` (fun () -> ( - let r = Ref.make 1 in - let () = r |> Ref.set 2 in - (r |> Ref.get) == 2 - |> Expect.is-true - )); - it `swap two refs` (fun () -> ( - let r1 = Ref.make 1 in - let r2 = Ref.make 2 in - let () = Ref.swap r1 r2 in - (Ref.get r1 == 2) && (Ref.get r2 == 1) - |> Expect.is-true - )); - it `set temporarily value of ref` (fun () -> ( - let r = Ref.make 1 in - let r-tmp-value = r |> Ref.set-temporarily 2 (fun _ -> (Ref.get r)) in - let r-value = Ref.get r in - (r-tmp-value == 2) && (r-value == 1) - |> Expect.is-true - )) - ]; - describe `String module` [ - it `check equality of strings` (fun () -> ( - Eq.equal String.eq `abc` `abc` - && not Eq.equal String.eq `abc` `abd` - |> Expect.is-true - )); - it `concatenate strings` (fun () -> ( - String.concat [`a`; `b`; `c`] - |> string-same `abc` - |> Expect.is-true - )); - it `check emptiness of string` (fun () -> ( - String.is-empty ` ` - && (not String.is-empty `hi`) - |> Expect.is-true - )); - it `split string with a given delimiter` (fun () -> ( - let delimiter = Char.make `;` in - `spam;ham;eggs;` - |> String.split-by delimiter - |> Eq.equal (List.eq String.eq) [`spam`; `ham`; `eggs`; ` `] - |> Expect.is-true - )); - it `convert a string to a list of characters` (fun () -> ( - let expected = [ - Char.make `a`; - Char.make `b`; - Char.make `c`; - ] in - String.to-list `abc` - |> Eq.equal (List.eq Char.eq) expected - |> Expect.is-true - )); - it `compare strings with lexicographical order` (fun () -> ( - let subject = Ord.compare String.ord in - [ - subject `a` `a`; - subject `a` `b`; - subject `ab` `ba`; - subject `aab` `aba`; - subject `bbb` `bbba`; - ] |> Eq.equal (List.eq Ordering.eq) [ - Eq; Lt; Lt; Lt; Lt; - ] |> Expect.is-true - )); - % TODO - % * sub - % * of-bool - % * of-int - % * of-float - % * of-codepoints - % * of-char - % * of-length - % * append - % * starts-with - % * ends-with - % * of-list - % * pow - % * split - % * split-by-first - % * lines - % * index - ] + ref-test-cases; + string-test-cases; ] |> run diff --git a/test/ref.test.satyg b/test/ref.test.satyg new file mode 100644 index 0000000..5618379 --- /dev/null +++ b/test/ref.test.satyg @@ -0,0 +1,32 @@ +@require: test/test +@require: test/expect + +@import: ../src/ref + +let ref-test-cases = open Test in + describe `Ref module` [ + it `make 1 contains 1` (fun () -> ( + (Ref.make 1 |> Ref.get) == 1 + |> Expect.is-true + )); + it `set overrides the value of ref` (fun () -> ( + let r = Ref.make 1 in + let () = r |> Ref.set 2 in + (r |> Ref.get) == 2 + |> Expect.is-true + )); + it `swap two refs` (fun () -> ( + let r1 = Ref.make 1 in + let r2 = Ref.make 2 in + let () = Ref.swap r1 r2 in + (Ref.get r1 == 2) && (Ref.get r2 == 1) + |> Expect.is-true + )); + it `set temporarily value of ref` (fun () -> ( + let r = Ref.make 1 in + let r-tmp-value = r |> Ref.set-temporarily 2 (fun _ -> (Ref.get r)) in + let r-value = Ref.get r in + (r-tmp-value == 2) && (r-value == 1) + |> Expect.is-true + )) + ] diff --git a/test/string.test.satyg b/test/string.test.satyg new file mode 100644 index 0000000..6dc4b18 --- /dev/null +++ b/test/string.test.satyg @@ -0,0 +1,74 @@ +@require: test/test +@require: test/expect + +@import: ../src/char +@import: ../src/eq +@import: ../src/list-ext +@import: ../src/ord +@import: ../src/string + +let string-test-cases = open Test in + describe `String module` [ + it `check equality of strings` (fun () -> ( + Eq.equal String.eq `abc` `abc` + && not Eq.equal String.eq `abc` `abd` + |> Expect.is-true + )); + it `concatenate strings` (fun () -> ( + String.concat [`a`; `b`; `c`] + |> string-same `abc` + |> Expect.is-true + )); + it `check emptiness of string` (fun () -> ( + String.is-empty ` ` + && (not String.is-empty `hi`) + |> Expect.is-true + )); + it `split string with a given delimiter` (fun () -> ( + let delimiter = Char.make `;` in + `spam;ham;eggs;` + |> String.split-by delimiter + |> Eq.equal (List.eq String.eq) [`spam`; `ham`; `eggs`; ` `] + |> Expect.is-true + )); + it `convert a string to a list of characters` (fun () -> ( + let expected = [ + Char.make `a`; + Char.make `b`; + Char.make `c`; + ] in + String.to-list `abc` + |> Eq.equal (List.eq Char.eq) expected + |> Expect.is-true + )); + it `compare strings with lexicographical order` (fun () -> ( + let subject = Ord.compare String.ord in + [ + subject `a` `a`; + subject `a` `b`; + subject `ab` `ba`; + subject `aab` `aba`; + subject `bbb` `bbba`; + ] |> Eq.equal (List.eq Ordering.eq) [ + Eq; Lt; Lt; Lt; Lt; + ] |> Expect.is-true + )); + % TODO + % * sub + % * of-bool + % * of-int + % * of-float + % * of-codepoints + % * of-char + % * of-length + % * append + % * starts-with + % * ends-with + % * of-list + % * pow + % * split + % * split-by-first + % * lines + % * index + ] + From f49e166303259966ddde87d06d850f8ce0355594 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sun, 14 Feb 2021 08:30:41 +0900 Subject: [PATCH 08/39] GH-142: Migrate unit tests for List module --- test/list.test.satyg | 79 ++++++++++++++++++++++++++++++++++++++++++++ test/main.test.saty | 2 ++ 2 files changed, 81 insertions(+) create mode 100644 test/list.test.satyg diff --git a/test/list.test.satyg b/test/list.test.satyg new file mode 100644 index 0000000..70a82e4 --- /dev/null +++ b/test/list.test.satyg @@ -0,0 +1,79 @@ +@require: test/test +@require: test/expect + +@import: ../src/int +@import: ../src/list-ext + +let list-test-cases = open Test in + describe `List module` [ + it `sort with bubblesort` (fun () -> ( + let l = [5;1;3;2;4] in + l |> List.bubblesort Int.ord + |> Eq.equal (List.eq Int.eq) [1;2;3;4;5] + |> Expect.is-true + )); + it `sort with insertsort` (fun () -> ( + let l = [5;1;3;2;4] in + l |> List.insertsort Int.ord + |> Eq.equal (List.eq Int.eq) [1;2;3;4;5] + |> Expect.is-true + )); + it `sort with mergesort` (fun () -> ( + let l = [5;1;3;2;4] in + l |> List.mergesort Int.ord + |> Eq.equal (List.eq Int.eq) [1;2;3;4;5] + |> Expect.is-true + )); + % TODO + % * eq + % * null + % * nil + % * cons + % * uncons + % * map + % * mapi + % * iter + % * iteri + % * filter + % * reverse + % * append + % * concat + % * length + % * nth + % * intersperse + % * find + % * apply + % * take + % * drop + % * take-while + % * drop-while + % * split-at + % * span + % * break + % * head + % * tail + % * last + % * init + % * reverse-append + % * reverse-map + % * all + % * any + % * zip + % * unzip + % * find + % * partition + % * iterate + % * repeat + % * cycle- + % * acons + % * max + % * min + % * fold + % % unstable API (may subject to change in the future) + % * fold-left + % * fold-lefti + % * fold-right + % * fold-left-adjacent + % * map-adjacent + % * mapi-adjacent + ] diff --git a/test/main.test.saty b/test/main.test.saty index 1becc57..b2bfff2 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -6,6 +6,7 @@ @import: ../src/ref @import: ../src/string +@import: list.test @import: ref.test @import: string.test @@ -13,5 +14,6 @@ open Test in describe `base` [ ref-test-cases; string-test-cases; + list-test-cases; ] |> run From f693b9256c6cd62095dd7033b4154831956c9740 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Mon, 15 Feb 2021 11:51:45 +0900 Subject: [PATCH 09/39] GH-142: Migrate unit tests for Array --- test/array.test.satyg | 64 +++++++++++++++++++++++++++++++++++++++++++ test/main.test.saty | 2 ++ 2 files changed, 66 insertions(+) create mode 100644 test/array.test.satyg diff --git a/test/array.test.satyg b/test/array.test.satyg new file mode 100644 index 0000000..e34357a --- /dev/null +++ b/test/array.test.satyg @@ -0,0 +1,64 @@ +@require: test/test +@require: test/expect + +@import: ../src/array +@import: ../src/eq +@import: ../src/fn +@import: ../src/int + +let array-test-cases = open Test in + % Note: We want (Array.eq : Array.t Eq.t) + let int-array-eq a b = + Eq.equal (List.eq Int.eq) (Array.to-list a) (Array.to-list b) in + describe `Array module` [ + it `make array and get contents and length` (fun () -> ( + let a = Array.make 3 2 in + (Array.get 0 a == 3) + && (Array.get 1 a == 3) + && (Array.length a == 2) + |> Expect.is-true + )); + it `initialize array with index` (fun () -> ( + let actual = Array.init (fun x -> x + 1) 10 in + actual + |> Array.to-list + |> Eq.equal (List.eq Int.eq) [1;2;3;4;5;6;7;8;9;10] + |> Expect.is-true + )); + it `overwrite value by index` (fun () -> ( + let actual = Array.init Fn.id 10 in + let is = [0;1;2;3;4;5;6;7;8;9] in + let () = is |> List.iter (fun i -> (Array.set i (10 - i) actual)) in + actual + |> Array.to-list + |> Eq.equal (List.eq Int.eq) [10;9;8;7;6;5;4;3;2;1] + |> Expect.is-true + )); + it `convert to list` (fun () -> ( + let a = Array.init Fn.id 10 in + let expected = [0;1;2;3;4;5;6;7;8;9] in + a + |> Array.to-list + |> Eq.equal (List.eq Int.eq) expected + |> Expect.is-true + )); + it `convert from list` (fun () -> ( + let actual = Array.of-list [0;1;2;3;4] in + let expected = Array.init Fn.id 5 in + actual + |> int-array-eq expected + |> Expect.is-true + )); + it `append arrays` (fun () -> ( + let a = Array.of-list [0;1;2;3;4] in + let b = Array.of-list [5;6;7;8;9] in + let expected = Array.of-list [0;1;2;3;4;5;6;7;8;9] in + Array.append a b + |> int-array-eq expected + |> Expect.is-true + )); + % TODO + % * concat + % * sub + % * map + ] diff --git a/test/main.test.saty b/test/main.test.saty index b2bfff2..3ac8699 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -6,6 +6,7 @@ @import: ../src/ref @import: ../src/string +@import: array.test @import: list.test @import: ref.test @import: string.test @@ -15,5 +16,6 @@ describe `base` [ ref-test-cases; string-test-cases; list-test-cases; + array-test-cases; ] |> run From 2ce415785a0df4258521f4b92377bfcee4507339 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Thu, 18 Feb 2021 00:25:08 +0900 Subject: [PATCH 10/39] GH-142: Migrate unit tests for RegExp module --- src/tuple.satyg | 10 ++++ test/main.test.saty | 2 + test/regex.test.satyg | 114 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 test/regex.test.satyg diff --git a/src/tuple.satyg b/src/tuple.satyg index ea00622..d378330 100644 --- a/src/tuple.satyg +++ b/src/tuple.satyg @@ -1,4 +1,5 @@ @stage: persistent +@import: eq module Unit : sig val make : unit @@ -11,9 +12,18 @@ module Pair : sig val fst : ('a * 'b) -> 'a val snd : ('a * 'b) -> 'b val swap : ('a * 'b) -> ('b * 'a) + + val eq : 'a Eq.t -> 'b Eq.t -> ('a * 'b) Eq.t end = struct let make x y = (x, y) let fst (x, _) = x let snd (_, y) = y let swap (x, y) = (y, x) + let eq a b = + Eq.make (fun x y -> ( + let (xa, xb) = x in + let (ya, yb) = y in + Eq.equal a xa ya + && Eq.equal b xb yb + )) end \ No newline at end of file diff --git a/test/main.test.saty b/test/main.test.saty index 3ac8699..a78263d 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -9,6 +9,7 @@ @import: array.test @import: list.test @import: ref.test +@import: regex.test @import: string.test open Test in @@ -17,5 +18,6 @@ describe `base` [ string-test-cases; list-test-cases; array-test-cases; + regex-test-cases; ] |> run diff --git a/test/regex.test.satyg b/test/regex.test.satyg new file mode 100644 index 0000000..1463ac6 --- /dev/null +++ b/test/regex.test.satyg @@ -0,0 +1,114 @@ +@require: test/test +@require: test/expect + +@import: ../src/regexp + +let regex-test-cases = open Test in + open RegExp in + let char-a = char (Char.make `a`) in + let char-b = char (Char.make `b`) in + let char-c = char (Char.make `c`) in + let result-eq = Eq.equal (List.eq (Option.eq (Pair.eq Int.eq String.eq))) in + describe `RegExp module` [ + % TODO: Do we need this? + % let () = RegExp.test (RegExp.of-string `ab.*ef`) `abcdef` |> String.of-bool |> Debug.log in + % let () = exec (compile (seq (many1 char-a) (many1 char-b))) `aabbb` |> String.of-bool |> Debug.log in + % let () = exec re-example1 `aabbb` |> String.of-bool |> Debug.log in + it `test "(a+)(b+)"` (fun () -> ( + let re1 = (seq (group (many1 char-a)) (group (many1 char-b))) in + let re2 = (alt char-a char-b) in + test re1 `aabbb` + && test re2 `aabbb` + |> Expect.is-true + )); + it `exec "(a+|(c))(b+)"` (fun () -> ( + let re = seq (group (alt (many1 char-a) (group char-c))) (group (many1 char-b)) in + exec re `aabbb` + |> result-eq [ + Option.some (0, `aabbb`); + Option.some (0, `aa`); + Option.none; + Option.some (2, `bbb`); + ] |> Expect.is-true + )); + % TODO GH-142: Is this right description? + it `test "a**"` (fun () -> ( + let re = many (many char-a) in + test re `aaaaa` + |> Expect.is-true + )); + % TODO GH-142: Is this right description? + it `exec "(.e)$"` (fun () -> ( + let re = seq (group (seq any (char (Char.make `e`)))) eof in + exec re `the apple` + % TODO GH-142: Is this right expectation? + |> result-eq [ + Option.some (7, `le`); + Option.some (7, `le`); + ] |> Expect.is-true + )); + it `exec "^apple$"` (fun () -> ( + let re = sequence [bol; string `apple`; eol] in + let text = `the apple +apple +leapple` in + exec re text + |> result-eq [ Option.some (10, `apple`) ] + |> Expect.is-true + )); + it `exec spaces` (fun () -> ( + exec spaces #` asdf`# + |> result-eq [ Option.some (0, #` `#)] + |> Expect.is-true + )); + it `compile and test "(a+|(c))(b+)"` (fun () -> ( + `aaabb` |> test (RegExp.of-string `(a+|(c))(b+)`) + |> Expect.is-true + )); + % let _ = RegExp.of-string `^\s\d$` in TODO GH-142: What do we wanna test? + % % let _ = RegExp.of-string `[]` in TODO GH-142: Do we wanna keep this? + % let _ = RegExp.of-string `[a-z]` in TODO GH-142: What do we wanna test? + it `match prefix of header of hexadecimal literal` (fun () -> ( + let re = (RegExp.of-string `0[xX]`) in + test re `0x` + && not test re `0a` + |> Expect.is-true + )); + it `match hexadecimal literal` (fun () -> ( + let re = (RegExp.of-string `0[xX][A-Fa-f0-9]+$`) in + test re `0x1f2e3d` + && not test re `0xaZb` + |> Expect.is-true + )); + it `idk what it is` (fun () -> ( % TODO GH-142: Please give right description + `][][` + |> test (RegExp.of-string `[][]+`) + |> Expect.is-true + )); + it `idk what it is 2` (fun () -> ( % TODO GH-142: Please give right description + `][]-[` + |> test (RegExp.of-string `[][-]+`) + |> Expect.is-true + )); + it `test against long input` (fun () -> ( + % NOTE GH-142: Do we want to set timelimit? + let input = ` I do not know why but it seems code2 is slow if it contains a long line. +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo +wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo` in + input + |> test (RegExp.of-string `wk`) + |> Expect.is-false + )) + ] From 5a35c5ccd475cd16e5f1e5bdef50c7cfe679bc9d Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Thu, 18 Feb 2021 00:28:50 +0900 Subject: [PATCH 11/39] GH-142: Fix EOF --- src/tuple.satyg | 2 +- test/string.test.satyg | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tuple.satyg b/src/tuple.satyg index d378330..04680f4 100644 --- a/src/tuple.satyg +++ b/src/tuple.satyg @@ -26,4 +26,4 @@ end = struct Eq.equal a xa ya && Eq.equal b xb yb )) -end \ No newline at end of file +end diff --git a/test/string.test.satyg b/test/string.test.satyg index 6dc4b18..143bd0f 100644 --- a/test/string.test.satyg +++ b/test/string.test.satyg @@ -71,4 +71,3 @@ let string-test-cases = open Test in % * lines % * index ] - From 13ad8bdea2b806855142917c32d5d98fba6c1e11 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Fri, 19 Feb 2021 09:27:45 +0900 Subject: [PATCH 12/39] GH-142: Fix type definition of Pair.eq --- src/tuple.satyg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tuple.satyg b/src/tuple.satyg index 04680f4..9570bb3 100644 --- a/src/tuple.satyg +++ b/src/tuple.satyg @@ -13,7 +13,7 @@ module Pair : sig val snd : ('a * 'b) -> 'b val swap : ('a * 'b) -> ('b * 'a) - val eq : 'a Eq.t -> 'b Eq.t -> ('a * 'b) Eq.t + val eq : ('a Eq.t) implicit -> ('b Eq.t) implicit -> (('a * 'b) Eq.t) implicit end = struct let make x y = (x, y) let fst (x, _) = x From 671493170706c28650a637dd765f7948a941d9af Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Fri, 19 Feb 2021 09:32:19 +0900 Subject: [PATCH 13/39] GH-142: Fix indent of String --- test/string.test.satyg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/string.test.satyg b/test/string.test.satyg index 143bd0f..7536a88 100644 --- a/test/string.test.satyg +++ b/test/string.test.satyg @@ -8,7 +8,7 @@ @import: ../src/string let string-test-cases = open Test in - describe `String module` [ + describe `String module` [ it `check equality of strings` (fun () -> ( Eq.equal String.eq `abc` `abc` && not Eq.equal String.eq `abc` `abd` From 0e3ff5de1bcabb2cc4e774b12294098685010a89 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Tue, 2 Mar 2021 06:30:07 +0900 Subject: [PATCH 14/39] GH-142: Migrate test cases for Int module --- test/int.test.satyg | 137 ++++++++++++++++++++++++++++++++++++++++++++ test/main.test.saty | 2 + 2 files changed, 139 insertions(+) create mode 100644 test/int.test.satyg diff --git a/test/int.test.satyg b/test/int.test.satyg new file mode 100644 index 0000000..a6088f8 --- /dev/null +++ b/test/int.test.satyg @@ -0,0 +1,137 @@ +@require: test/test +@require: test/expect + +@import: ../src/int +@import: ../src/list-ext +@import: ../src/option-ext + +let int-test-cases = open Test in + describe `Int module` [ + it `calculate logical shift left` (fun () -> ( + 13 + |> Int.lsl 2 + |> (==) 52 + |> Expect.is-true + )); + it `calculate arithmetic shift right of positive` (fun () -> ( + [0; 1; 2; 3; 4; 5] + |> List.map (fun x -> 13 |> Int.asr x) + |> Eq.equal (List.eq Int.eq) [13; 6; 3; 1; 0; 0] + |> Expect.is-true + )); + it `calculate arithmetic shift right of negative` (fun () -> ( + [0; 1; 2; 3; 4; 5] + |> List.map (fun x -> -13 |> Int.asr x) + |> Eq.equal (List.eq Int.eq) [-13; -7; -4; -2; -1; -1] + |> Expect.is-true + )); + it `calculate logical and` (fun () -> ( + (10 |> Int.land 13) == 8 + && (31 |> Int.land (-13)) == 19 + |> Expect.is-true + )); + it `calculate logical or` (fun () -> ( + 10 + |> Int.lor 13 + |> (==) 15 + |> Expect.is-true + )); + it `calculate logical exclusive or` (fun () -> ( + 10 + |> Int.lxor 13 + |> (==) 7 + |> Expect.is-true + )); + it `calculate logical shift right` (fun () -> ( + (13 + |> Int.lsr 2 + |> (==) 3) + && (-13 + |> Int.lsr 2 + |> (==) 2305843009213693948) + |> Expect.is-true + )); + it `parse decimal number` (fun () -> ( + `12345678` + |> Int.of-string ?:10 + |> (==) 12345678 + |> Expect.is-true + )); + it `parse negative decimal number` (fun () -> ( + `-123` + |> Int.of-string ?:10 + |> (==) (-123) + |> Expect.is-true + )); + it `parse hexadecimal number` (fun () -> ( + `ffff` + |> Int.of-string ?:16 + |> (==) 65535 + |> Expect.is-true + )); + it `calculate power` (fun () -> ( + (2 |> Int.pow 3 |> (==) 8) + && (2 |> Int.pow 0 |> (==) 1) + |> Expect.is-true + )); + it `calculate supreme from a list of numbers` (fun () -> ( + Int.sup [1; 3; 2] + |> (==) 3 + |> Expect.is-true + )); + it `calculate supreme from an empty list` (fun () -> ( + %% SATySFi compiler fails to parse -4611686018427387904 + let expected = Int.of-string ?:10 `-4611686018427387904` in + Int.sup [] + |> (==) expected + |> Expect.is-true + )); + it `parse maybe decimal` (fun () -> ( + `123` + |> Int.of-string-opt ?:10 + |> Eq.equal (Option.eq Int.eq) (Option.some 123) + |> Expect.is-true + )); + it `parse maybe negative decimal` (fun () -> ( + `-123` + |> Int.of-string-opt ?:10 + |> Eq.equal (Option.eq Int.eq) (Option.some (-123)) + |> Expect.is-true + )); + it `fail to parse non decimal` (fun () -> ( + `12n` + |> Int.of-string-opt ?:10 + |> Eq.equal (Option.eq Int.eq) Option.none + |> Expect.is-true + )); + it `parse maybe hexadecimal` (fun () -> ( + `a` + |> Int.of-string-opt ?:16 + |> Eq.equal (Option.eq Int.eq) (Option.some 10) + |> Expect.is-true + )); + % TODO + % ord + % eq + % equal + % bitsize + % max-value + % min-value + % (<) + % (>) + % (>=) + % (<=) + % (==) + % succ + % pred + % neg + % add + % sub + % mul + % div + % abs + % max + % min + % inf + % to-string + ] diff --git a/test/main.test.saty b/test/main.test.saty index a78263d..7830ad6 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -7,6 +7,7 @@ @import: ../src/string @import: array.test +@import: int.test @import: list.test @import: ref.test @import: regex.test @@ -19,5 +20,6 @@ describe `base` [ list-test-cases; array-test-cases; regex-test-cases; + int-test-cases; ] |> run From d6f8cf9776ff8468f2d3c7ff5bcc185fdffcffa9 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sat, 2 Mar 2024 20:51:33 +0900 Subject: [PATCH 15/39] GH-142: Migrate added test cases of String --- __test__/satysrc/generic.saty | 35 --------------------- test/string.test.satyg | 57 +++++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 51 deletions(-) diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index 32cd9bd..96b8220 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -39,41 +39,6 @@ open Fn in -let () = Debug.log `==== Ref ====` in -let r = Ref.make 1 in -let () = r |> Ref.get |> String.of-int |> Debug.log in -let () = r |> Ref.set 2 in -let () = r |> Ref.get |> String.of-int |> Debug.log in -let r1 = Ref.make 1 in -let r2 = Ref.make 2 in -let () = Ref.swap r1 r2 in -let () = Debug.log (String.of-int (Ref.get r1) ^ `:` ^ String.of-int (Ref.get r2)) in % 2:1 -let r = Ref.make 1 in -let () = r |> Ref.set-temporarily 2 (fun _ -> Debug.log (String.of-int (Ref.get r))) in % 2 -let () = Debug.log (String.of-int (Ref.get r)) in % 1 - -let () = Debug.log `==== String ====` in -let () = Debug.log (String.concat [`a`; `b`; `c`;]) in -let () = Debug.log (String.concat ?:(`;`) [`a`; `b`; `c`;]) in -let () = Debug.log (String.of-bool (String.is-empty ` `)) in % true -let _ = String.split-by (Char.make `;`) `spam;ham;eggs;` |> List.map Debug.log in -let _ = String.to-list `abc` |> List.map (fun c -> (c |> String.of-char |> Debug.log)) in -let () = String.(`a` < `b`) |> Bool.to-string |> Debug.log in % true -let () = String.(`ab` < `ba`) |> Bool.to-string |> Debug.log in % true -let () = String.(`aab` < `aba`) |> Bool.to-string |> Debug.log in % true -let () = String.(`bbb` < `bbba`) |> Bool.to-string |> Debug.log in % true -let () = String.contains `abc` `1abcdef` |> Bool.to-string |> Debug.log in % true -let () = String.contains `abc` `abdef` |> Bool.to-string |> Debug.log in % false -let () = String.contains `abc` `ef` |> Bool.to-string |> Debug.log in % false -let () = String.trim #` abc `# |> Debug.log in % |abc| -let () = String.trim #` `# |> Debug.log in % || -let () = String.trim-start #` abc `# |> Debug.log in % |abc | -let () = String.trim-end #` abc `# |> Debug.log in % | abc| -let () = String.uppercase-ascii `Grüße, Jürgen` |> Debug.log in % GRüßE, JüRGEN -let () = String.lowercase-ascii `GRÜßE, JÜRGEN` |> Debug.log in % grÜße, jÜrgen -let () = String.capitalize-ascii `tiTle` |> Debug.log in % TiTle -let () = String.uncapitalize-ascii `TiTle` |> Debug.log in % tiTle - let () = Debug.log `==== List ====` in let lst = [1;3;2;4;5] in let () = lst |> List.take 0 |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in % ` ` diff --git a/test/string.test.satyg b/test/string.test.satyg index 7536a88..9b9f027 100644 --- a/test/string.test.satyg +++ b/test/string.test.satyg @@ -8,15 +8,22 @@ @import: ../src/string let string-test-cases = open Test in + let streq = Eq.equal String.eq in + let strleq = Eq.equal (List.eq String.eq) in describe `String module` [ it `check equality of strings` (fun () -> ( - Eq.equal String.eq `abc` `abc` - && not Eq.equal String.eq `abc` `abd` + streq `abc` `abc` + && not streq `abc` `abd` |> Expect.is-true )); it `concatenate strings` (fun () -> ( String.concat [`a`; `b`; `c`] - |> string-same `abc` + |> streq `abc` + |> Expect.is-true + )); + it `concatenate strings with delimiter` (fun () -> ( + String.concat ?:(`;`) [`a`; `b`; `c`] + |> streq `a;b;c` |> Expect.is-true )); it `check emptiness of string` (fun () -> ( @@ -26,33 +33,51 @@ let string-test-cases = open Test in )); it `split string with a given delimiter` (fun () -> ( let delimiter = Char.make `;` in - `spam;ham;eggs;` - |> String.split-by delimiter - |> Eq.equal (List.eq String.eq) [`spam`; `ham`; `eggs`; ` `] + String.split-by delimiter `spam;ham;eggs;` + |> strleq [`spam`; `ham`; `eggs`; ` `] |> Expect.is-true )); it `convert a string to a list of characters` (fun () -> ( - let expected = [ + String.to-list `abc` + |> Eq.equal (List.eq Char.eq) [ Char.make `a`; Char.make `b`; Char.make `c`; - ] in - String.to-list `abc` - |> Eq.equal (List.eq Char.eq) expected + ] |> Expect.is-true )); it `compare strings with lexicographical order` (fun () -> ( - let subject = Ord.compare String.ord in + let strcmp = Ord.compare String.ord in [ - subject `a` `a`; - subject `a` `b`; - subject `ab` `ba`; - subject `aab` `aba`; - subject `bbb` `bbba`; + strcmp `a` `a`; + strcmp `a` `b`; + strcmp `ab` `ba`; + strcmp `aab` `aba`; + strcmp `bbb` `bbba`; ] |> Eq.equal (List.eq Ordering.eq) [ Eq; Lt; Lt; Lt; Lt; ] |> Expect.is-true )); + it `check containment` (fun () -> ( + String.contains `abc` `1abcdef` + && not String.contains `abc` `abdef` + && not String.contains `abc` `ef` + |> Expect.is-true + )); + it `trim heading and trailing spaces` (fun () -> ( + streq (String.trim #` abc `#) `abc` + && streq (String.trim #` `#) ` ` + && streq (String.trim-start #` abc `#) #`abc `# + && streq (String.trim-end #` abc `#) #` abc`# + |> Expect.is-true + )); + it `change case of ascii` (fun () -> + streq (String.uppercase-ascii `Grüße, Jürgen`) `GRüßE, JüRGEN` + && streq (String.lowercase-ascii `GRÜßE, JÜRGEN`) `grÜße, jÜrgen` + && streq (String.capitalize-ascii `tiTle`) `TiTle` + && streq (String.uncapitalize-ascii `TiTle`) `tiTle` + |> Expect.is-true + ) % TODO % * sub % * of-bool From ab9d894de7dc3a815417276ede20d800b4b021ee Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sat, 2 Mar 2024 21:34:13 +0900 Subject: [PATCH 16/39] GH-142: Migrate added tests of List --- __test__/satysrc/generic.saty | 20 --------------- test/list.test.satyg | 47 ++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index 96b8220..52b725e 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -39,26 +39,6 @@ open Fn in -let () = Debug.log `==== List ====` in -let lst = [1;3;2;4;5] in -let () = lst |> List.take 0 |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in % ` ` -let () = lst |> List.take 1 |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in % `1` -let () = lst |> List.take 7 |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in % `13245` -let () = lst |> List.drop 0 |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in % `13245` -let () = lst |> List.drop 2 |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in % `245` -let () = lst |> List.drop 7 |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in % `` -let () = lst |> List.split-at 3 |> (fun (xs,_) -> xs) |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in % `132` -let () = lst |> List.split-at 3 |> (fun (_,ys) -> ys) |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in % `45` -let () = lst |> List.bubblesort Int.ord |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in -let () = lst |> List.insertsort Int.ord |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in -let () = lst |> List.mergesort Int.ord |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in -let lst = [(1,2);(2,1);(1,1)] in -let ord = Ord.make (fun (n1,_) (n2,_) -> Ord.compare Int.ord n1 n2) in -let show (n1,n2) = `(` ^ String.of-int n1 ^ `,` ^ String.of-int n2 ^ `)` in -let () = lst |> List.bubblesort ord |> List.map show |> List.fold-left (^) ` ` |> Debug.log in -let () = lst |> List.insertsort ord |> List.map show |> List.fold-left (^) ` ` |> Debug.log in -let () = lst |> List.mergesort ord |> List.map show |> List.fold-left (^) ` ` |> Debug.log in - let () = Debug.log `==== Array ====` in let a = Array.make 3 42 in let () = a |> Array.get 0 |> String.of-int |> Debug.log in diff --git a/test/list.test.satyg b/test/list.test.satyg index 70a82e4..4a0c19c 100644 --- a/test/list.test.satyg +++ b/test/list.test.satyg @@ -3,25 +3,47 @@ @import: ../src/int @import: ../src/list-ext +@import: ../src/tuple let list-test-cases = open Test in + let intleq = Eq.equal (List.eq Int.eq) in describe `List module` [ - it `sort with bubblesort` (fun () -> ( - let l = [5;1;3;2;4] in - l |> List.bubblesort Int.ord - |> Eq.equal (List.eq Int.eq) [1;2;3;4;5] + it `take elements` (fun () -> ( + let lst = [1;3;2;4;5] in + intleq (List.take 0 lst) [] + && intleq (List.take 1 lst) [1] + && intleq (List.take 7 lst) [1;3;2;4;5] |> Expect.is-true )); - it `sort with insertsort` (fun () -> ( - let l = [5;1;3;2;4] in - l |> List.insertsort Int.ord - |> Eq.equal (List.eq Int.eq) [1;2;3;4;5] + it `drop elements` (fun () -> ( + let lst = [1;3;2;4;5] in + intleq (List.drop 0 lst) [1;3;2;4;5] + && intleq (List.drop 2 lst) [2;4;5] + && intleq (List.drop 7 lst) [] + |> Expect.is-true + )); + it `split at the given index` (fun () -> ( + List.split-at 3 [1;3;2;4;5] + |> Eq.equal (Pair.eq (List.eq Int.eq) (List.eq Int.eq)) + ([1;3;2], [4;5]) |> Expect.is-true )); - it `sort with mergesort` (fun () -> ( + it `sort list` (fun () -> ( let l = [5;1;3;2;4] in - l |> List.mergesort Int.ord - |> Eq.equal (List.eq Int.eq) [1;2;3;4;5] + let expected = [1;2;3;4;5] in + (List.bubblesort Int.ord l |> intleq expected) + && (List.insertsort Int.ord l |> intleq expected) + && (List.mergesort Int.ord l |> intleq expected) + |> Expect.is-true + )); + it `sort with custom ord` (fun () -> ( + let l = [(1,2);(2,1);(1,1)] in + let expected = [(1,2);(1,1);(2,1)] in + let ord = Ord.make (fun (n1,_) (n2,_) -> Ord.compare Int.ord n1 n2) in + let eq = Eq.equal (List.eq (Pair.eq Int.eq Int.eq)) in + (List.bubblesort ord l |> eq expected) + && (List.insertsort ord l |> eq expected) + && (List.mergesort ord l |> eq expected) |> Expect.is-true )); % TODO @@ -43,11 +65,8 @@ let list-test-cases = open Test in % * intersperse % * find % * apply - % * take - % * drop % * take-while % * drop-while - % * split-at % * span % * break % * head From 46d02a85fa4d5c8f26821b84812f5717d9dc0242 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sun, 3 Mar 2024 08:54:36 +0900 Subject: [PATCH 17/39] GH-142: Migrate added tests of Array --- __test__/satysrc/generic.saty | 19 ----------------- test/array.test.satyg | 39 +++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index 52b725e..8946e2b 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -38,25 +38,6 @@ @import: ../../src/big-int open Fn in - -let () = Debug.log `==== Array ====` in -let a = Array.make 3 42 in -let () = a |> Array.get 0 |> String.of-int |> Debug.log in -let () = a |> Array.set 0 43 in -let () = a |> Array.get 0 |> String.of-int |> Debug.log in -let a = 10 |> Array.init id in -let is = [0;1;2;3;4;5;6;7;8;9] in -let () = is |> List.iter (fun i -> a |> Array.get i |> String.of-int |> Debug.log) in -let () = is |> List.iter (fun i -> a |> Array.set i (10 - i)) in -let () = is |> List.iter (fun i -> a |> Array.get i |> String.of-int |> Debug.log) in -let () = a |> Array.to-list |> List.iter (fun i -> i |> String.of-int |> Debug.log) in -let () = [0;1;2;3;4;] |> Array.of-list |> Array.sub 2 3 |> Array.to-list |> List.map String.of-int |> List.fold-left (^) ` ` |> Debug.log in % `234` -let a1 = Array.of-list [0;1;2;3;4;] in -let a2 = Array.of-list [5;6;7;8;9] in -let a = Array.append a1 a2 in -let () = Debug.log (String.of-int (Array.get 0 a)) in -let () = Array.append a1 a2 |> Array.to-list |> List.iter (fun i -> i |> String.of-int |> Debug.log) in - let () = Debug.log `==== RegExp ====` in open RegExp in %let () = RegExp.test (RegExp.of-string `ab.*ef`) `abcdef` |> String.of-bool |> Debug.log in diff --git a/test/array.test.satyg b/test/array.test.satyg index e34357a..9961095 100644 --- a/test/array.test.satyg +++ b/test/array.test.satyg @@ -8,9 +8,16 @@ let array-test-cases = open Test in % Note: We want (Array.eq : Array.t Eq.t) - let int-array-eq a b = + let intaeq a b = Eq.equal (List.eq Int.eq) (Array.to-list a) (Array.to-list b) in + let eq-to-intl l a = Eq.equal (List.eq Int.eq) l (Array.to-list a) in describe `Array module` [ + it `checks equality of arrays (test util function)` (fun () -> ( + intaeq (Array.make 3 2) (Array.make 3 2) + && not intaeq (Array.make 3 2) (Array.make 4 2) + && not intaeq (Array.make 3 2) (Array.make 3 1) + |> Expect.is-true + )); it `make array and get contents and length` (fun () -> ( let a = Array.make 3 2 in (Array.get 0 a == 3) @@ -18,20 +25,12 @@ let array-test-cases = open Test in && (Array.length a == 2) |> Expect.is-true )); - it `initialize array with index` (fun () -> ( - let actual = Array.init (fun x -> x + 1) 10 in - actual - |> Array.to-list - |> Eq.equal (List.eq Int.eq) [1;2;3;4;5;6;7;8;9;10] - |> Expect.is-true - )); it `overwrite value by index` (fun () -> ( - let actual = Array.init Fn.id 10 in - let is = [0;1;2;3;4;5;6;7;8;9] in - let () = is |> List.iter (fun i -> (Array.set i (10 - i) actual)) in - actual - |> Array.to-list - |> Eq.equal (List.eq Int.eq) [10;9;8;7;6;5;4;3;2;1] + let a = Array.make 3 2 in + let () = a |> Array.set 0 43 in + (Array.get 0 a == 43) + && (Array.get 1 a == 3) + && (Array.length a == 2) |> Expect.is-true )); it `convert to list` (fun () -> ( @@ -46,19 +45,23 @@ let array-test-cases = open Test in let actual = Array.of-list [0;1;2;3;4] in let expected = Array.init Fn.id 5 in actual - |> int-array-eq expected + |> intaeq expected + |> Expect.is-true + )); + it `make subarray` (fun () -> ( + Array.of-list [0;1;2;3;4] + |> Array.sub 2 3 + |> eq-to-intl [2;3;4] |> Expect.is-true )); it `append arrays` (fun () -> ( let a = Array.of-list [0;1;2;3;4] in let b = Array.of-list [5;6;7;8;9] in - let expected = Array.of-list [0;1;2;3;4;5;6;7;8;9] in Array.append a b - |> int-array-eq expected + |> eq-to-intl [0;1;2;3;4;5;6;7;8;9] |> Expect.is-true )); % TODO % * concat - % * sub % * map ] From 6a21bb60124fa2e5950b67236a84d93b7017d4c4 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sun, 3 Mar 2024 09:20:17 +0900 Subject: [PATCH 18/39] GH-142: Migrate added tests of Int --- __test__/satysrc/generic.saty | 41 ------------------- test/int.test.satyg | 74 ++++++++++++----------------------- 2 files changed, 24 insertions(+), 91 deletions(-) diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index 8946e2b..5e44b62 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -142,47 +142,6 @@ let rules = [ let (Some tokens) = Lexer.lex rules `abc defg hijklMNL op123 ` in let () = tokens |> List.iter (fun tk -> (Debug.log (`(| kind = `# ^ tk#kind ^ `, data = "`# ^ tk#data ^ `" |)`))) in -let () = Debug.log `==== Int ====` in -let p i = i |> String.of-int |> Debug.log in -let () = p (13 |> Int.lsl 2) in %==52 -let () = p (13 |> Int.asr 0) in %==13 -let () = p (13 |> Int.asr 1) in %==6 -let () = p (13 |> Int.asr 2) in %==3 -let () = p (13 |> Int.asr 3) in %==1 -let () = p (13 |> Int.asr 4) in %==0 -let () = p (13 |> Int.asr 5) in %==0 -let () = p (-13 |> Int.asr 0) in %==-13 -let () = p (-13 |> Int.asr 1) in %==-7 -let () = p (-13 |> Int.asr 2) in %==-4 -let () = p (-13 |> Int.asr 3) in %==-2 -let () = p (-13 |> Int.asr 4) in %==-1 -let () = p (-13 |> Int.asr 5) in %==-1 -let () = p (13 |> Int.land 10) in %==8 -let () = p (-13 |> Int.land 31) in %==19 -let () = p (13 |> Int.lor 10) in %==15 -let () = p (13 |> Int.lxor 10) in %==7 -let () = p (13 |> Int.lsr 2) in %==3 -let () = p (-13 |> Int.lsr 2) in %==2305843009213693948 -let () = p (`12345678` |> Int.of-string ?:10) in -let () = p (`-123` |> Int.of-string ?:10) in -let () = p (`ffff` |> Int.of-string ?:16) in -let () = p (2 |> Int.pow 3) in -let () = p (2 |> Int.pow 0) in -let () = p (Int.sup [1; 3; 2]) in -let () = p (Int.sup []) in -let p-opt o = - let s = - match o with - | None -> `None` - | Some(i) -> `Some(` ^ Int.to-string i ^ `)` - in - Debug.log s -in -let () = p-opt(`123` |> Int.of-string-opt ?:10) in -let () = p-opt(`-123` |> Int.of-string-opt ?:10) in -let () = p-opt(`12n` |> Int.of-string-opt ?:10) in -let () = p-opt(`a` |> Int.of-string-opt ?:16) in - let () = Debug.log `==== Map ====` in let m = Map.of-list [(1, `a`); (2, `b`); (3, `c`)] in let option-force (Some v) = v in diff --git a/test/int.test.satyg b/test/int.test.satyg index a6088f8..e9bbcbf 100644 --- a/test/int.test.satyg +++ b/test/int.test.satyg @@ -6,23 +6,23 @@ @import: ../src/option-ext let int-test-cases = open Test in + let intleq = Eq.equal (List.eq Int.eq) in + let intoeq = Eq.equal (Option.eq Int.eq) in describe `Int module` [ it `calculate logical shift left` (fun () -> ( - 13 - |> Int.lsl 2 - |> (==) 52 + (13 |> Int.lsl 2) == 52 |> Expect.is-true )); it `calculate arithmetic shift right of positive` (fun () -> ( [0; 1; 2; 3; 4; 5] |> List.map (fun x -> 13 |> Int.asr x) - |> Eq.equal (List.eq Int.eq) [13; 6; 3; 1; 0; 0] + |> intleq [13; 6; 3; 1; 0; 0] |> Expect.is-true )); it `calculate arithmetic shift right of negative` (fun () -> ( [0; 1; 2; 3; 4; 5] |> List.map (fun x -> -13 |> Int.asr x) - |> Eq.equal (List.eq Int.eq) [-13; -7; -4; -2; -1; -1] + |> intleq [-13; -7; -4; -2; -1; -1] |> Expect.is-true )); it `calculate logical and` (fun () -> ( @@ -31,83 +31,57 @@ let int-test-cases = open Test in |> Expect.is-true )); it `calculate logical or` (fun () -> ( - 10 - |> Int.lor 13 - |> (==) 15 + (10 |> Int.lor 13) == 15 |> Expect.is-true )); it `calculate logical exclusive or` (fun () -> ( - 10 - |> Int.lxor 13 - |> (==) 7 + (10 |> Int.lxor 13) == 7 |> Expect.is-true )); it `calculate logical shift right` (fun () -> ( - (13 - |> Int.lsr 2 - |> (==) 3) - && (-13 - |> Int.lsr 2 - |> (==) 2305843009213693948) + (13 |> Int.lsr 2) == 3 + && (-13 |> Int.lsr 2) == 2305843009213693948 |> Expect.is-true )); - it `parse decimal number` (fun () -> ( - `12345678` - |> Int.of-string ?:10 - |> (==) 12345678 - |> Expect.is-true - )); - it `parse negative decimal number` (fun () -> ( - `-123` - |> Int.of-string ?:10 - |> (==) (-123) - |> Expect.is-true - )); - it `parse hexadecimal number` (fun () -> ( - `ffff` - |> Int.of-string ?:16 - |> (==) 65535 + it `parse number with given base` (fun () -> ( + (`12345678` |> Int.of-string ?:10) == 12345678 + && (`-123` |> Int.of-string ?:10) == -123 + && (`ffff` |> Int.of-string ?:16) == 65535 |> Expect.is-true )); it `calculate power` (fun () -> ( - (2 |> Int.pow 3 |> (==) 8) - && (2 |> Int.pow 0 |> (==) 1) + (2 |> Int.pow 3) == 8 + && (2 |> Int.pow 0) == 1 |> Expect.is-true )); it `calculate supreme from a list of numbers` (fun () -> ( - Int.sup [1; 3; 2] - |> (==) 3 + (Int.sup [1; 3; 2]) == 3 |> Expect.is-true )); it `calculate supreme from an empty list` (fun () -> ( %% SATySFi compiler fails to parse -4611686018427387904 let expected = Int.of-string ?:10 `-4611686018427387904` in - Int.sup [] - |> (==) expected + (Int.sup []) == expected |> Expect.is-true )); it `parse maybe decimal` (fun () -> ( - `123` - |> Int.of-string-opt ?:10 + `123` |> Int.of-string-opt ?:10 |> Eq.equal (Option.eq Int.eq) (Option.some 123) |> Expect.is-true )); it `parse maybe negative decimal` (fun () -> ( - `-123` - |> Int.of-string-opt ?:10 - |> Eq.equal (Option.eq Int.eq) (Option.some (-123)) + `-123` |> Int.of-string-opt ?:10 + |> intoeq (Option.some (-123)) |> Expect.is-true )); it `fail to parse non decimal` (fun () -> ( - `12n` - |> Int.of-string-opt ?:10 - |> Eq.equal (Option.eq Int.eq) Option.none + `12n` |> Int.of-string-opt ?:10 + |> intoeq Option.none |> Expect.is-true )); it `parse maybe hexadecimal` (fun () -> ( - `a` - |> Int.of-string-opt ?:16 - |> Eq.equal (Option.eq Int.eq) (Option.some 10) + `a` |> Int.of-string-opt ?:16 + |> intoeq (Option.some 10) |> Expect.is-true )); % TODO From ee635a960202d12cdbe01fbb489ff420f7d64637 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sun, 3 Mar 2024 11:15:11 +0900 Subject: [PATCH 19/39] GH-142: Refine tests of Regex --- __test__/satysrc/generic.saty | 44 +---------------------------------- test/regex.test.satyg | 28 ++++++++++++++-------- 2 files changed, 19 insertions(+), 53 deletions(-) diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index 5e44b62..7cc6809 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -52,49 +52,6 @@ let print-result r = let char-a = char (Char.make `a`) in let char-b = char (Char.make `b`) in let char-c = char (Char.make `c`) in -% (a+)(b+) -let () = test (seq (group (many1 char-a)) (group (many1 char-b))) `aabbb` |> String.of-bool |> Debug.log in % true -let () = `aabbb` |> test (alt char-a char-b) |> String.of-bool |> Debug.log in % true -% (a+|(c))(b+) -let re1 = seq (group (alt (many1 char-a) (group char-c))) (group (many1 char-b)) in -let ss = exec re1 `aabbb` |> print-result in -let re3 = many (many char-a) in -let () = `aaaaa` |> test re3 |> String.of-bool |> Debug.log in -let re4 = seq (group (seq any (char (Char.make `e`)))) eof in -let () = `the apple` |> exec re4 |> print-result in -let re6 = sequence [bol; string `apple`; eol] in -let () = `the apple -apple -leapple` |> exec re6 |> print-result in -let () = exec spaces #` asdf`# |> print-result in -let () = `aaabb` |> test (RegExp.of-string `(a+|(c))(b+)`) |> String.of-bool |> Debug.log in -let _ = RegExp.of-string `^\s\d$` in -% let _ = RegExp.of-string `[]` in -let _ = RegExp.of-string `[a-z]` in -let _ = `0X` |> test (RegExp.of-string `0[xX]`) |> String.of-bool |> Debug.log in -let _ = `0x1f2e3d` |> test (RegExp.of-string `0[xX][A-Fa-f0-9]+`) |> String.of-bool |> Debug.log in -let _ = `0a` |> test (RegExp.of-string `0[xX]`) |> String.of-bool |> Debug.log in -let _ = `0xaZb` |> test (RegExp.of-string `^0[xX][A-Fa-f0-9]+$`) |> String.of-bool |> Debug.log in -let _ = `][][` |> test (RegExp.of-string `[][]+`) |> String.of-bool |> Debug.log in -let _ = `][]-[` |> test (RegExp.of-string `[][-]+`) |> String.of-bool |> Debug.log in -let input = ` I do not know why but it seems code2 is slow if it contains a long line. -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo -wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo` in -let pat = `wk` in -let () = Debug.print `testing long input` in -let () = Debug.print (String.of-bool (RegExp.test (RegExp.of-string pat) input)) in let () = Debug.log `==== Parser ====` in let () = @@ -142,6 +99,7 @@ let rules = [ let (Some tokens) = Lexer.lex rules `abc defg hijklMNL op123 ` in let () = tokens |> List.iter (fun tk -> (Debug.log (`(| kind = `# ^ tk#kind ^ `, data = "`# ^ tk#data ^ `" |)`))) in + let () = Debug.log `==== Map ====` in let m = Map.of-list [(1, `a`); (2, `b`); (3, `c`)] in let option-force (Some v) = v in diff --git a/test/regex.test.satyg b/test/regex.test.satyg index 1463ac6..42f56dc 100644 --- a/test/regex.test.satyg +++ b/test/regex.test.satyg @@ -15,10 +15,12 @@ let regex-test-cases = open Test in % let () = exec (compile (seq (many1 char-a) (many1 char-b))) `aabbb` |> String.of-bool |> Debug.log in % let () = exec re-example1 `aabbb` |> String.of-bool |> Debug.log in it `test "(a+)(b+)"` (fun () -> ( - let re1 = (seq (group (many1 char-a)) (group (many1 char-b))) in - let re2 = (alt char-a char-b) in - test re1 `aabbb` - && test re2 `aabbb` + test (seq (group (many1 char-a)) (group (many1 char-b))) `aabbb` + |> Expect.is-true + )); + % TODO GH-142: Is this right description? + it `test "a|b"` (fun () -> ( + test (alt char-a char-b) `aabbb` |> Expect.is-true )); it `exec "(a+|(c))(b+)"` (fun () -> ( @@ -33,8 +35,7 @@ let regex-test-cases = open Test in )); % TODO GH-142: Is this right description? it `test "a**"` (fun () -> ( - let re = many (many char-a) in - test re `aaaaa` + test (many (many char-a)) `aaaaa` |> Expect.is-true )); % TODO GH-142: Is this right description? @@ -65,12 +66,19 @@ leapple` in `aaabb` |> test (RegExp.of-string `(a+|(c))(b+)`) |> Expect.is-true )); - % let _ = RegExp.of-string `^\s\d$` in TODO GH-142: What do we wanna test? - % % let _ = RegExp.of-string `[]` in TODO GH-142: Do we wanna keep this? - % let _ = RegExp.of-string `[a-z]` in TODO GH-142: What do we wanna test? + it `compile "^\s\d" successfully` (fun () -> ( + let _ = RegExp.of-string `^\s\d$` in + Expect.always-pass + )); + % fails to compile "[]" + it `compile "[a-z]" successfully` (fun () -> ( + let _ = RegExp.of-string `[a-z]` in + Expect.always-pass + )); it `match prefix of header of hexadecimal literal` (fun () -> ( let re = (RegExp.of-string `0[xX]`) in test re `0x` + && test re `0X` && not test re `0a` |> Expect.is-true )); @@ -90,7 +98,7 @@ leapple` in |> test (RegExp.of-string `[][-]+`) |> Expect.is-true )); - it `test against long input` (fun () -> ( + it `failing test with long input won't take that long` (fun () -> ( % NOTE GH-142: Do we want to set timelimit? let input = ` I do not know why but it seems code2 is slow if it contains a long line. wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo wakegawakaranaiyo From 02dd6d549f2161ea42e28e3c66c4296abad812bb Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sun, 3 Mar 2024 12:56:48 +0900 Subject: [PATCH 20/39] GH-142: Migrate tests of Parser --- __test__/satysrc/generic.saty | 38 ------------------------- test/main.test.saty | 10 ++++--- test/parser.test.satyg | 52 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 42 deletions(-) create mode 100644 test/parser.test.satyg diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index 7cc6809..07a1ae3 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -37,45 +37,7 @@ @import: ../../src/tree-map @import: ../../src/big-int -open Fn in -let () = Debug.log `==== RegExp ====` in -open RegExp in -%let () = RegExp.test (RegExp.of-string `ab.*ef`) `abcdef` |> String.of-bool |> Debug.log in -let print-result r = - r |> List.iter (fun s -> ( - match s with - | None -> Debug.log `None` - | Some (i, s) -> Debug.log (`Some(` ^ String.of-int i ^ `, "` ^ s ^ `")`) - )) in -%let () = exec (compile (seq (many1 char-a) (many1 char-b))) `aabbb` |> String.of-bool |> Debug.log in -%let () = exec re-example1 `aabbb` |> String.of-bool |> Debug.log in -let char-a = char (Char.make `a`) in -let char-b = char (Char.make `b`) in -let char-c = char (Char.make `c`) in - let () = Debug.log `==== Parser ====` in -let () = - open Parser in - `aaa` |> StringParser.run (many (StringParser.char (Char.make `a`)) >>= (fun cs -> (Debug.log (String.of-list cs) before ret cs))) |> Fn.ignore in - -let () = - open Parser in - open StringParser in - let op name f = string name >> ret f in - let addop = op `+` Int.add in - let subop = op `-` Int.sub in - let mulop = op `*` Int.mul in - let divop = op `/` Int.div in - let number = some digit >>= (fun cs -> ret (Int.of-string (String.of-list cs))) in - let expr = fix (fun expr -> ( - let factor = between (string `(`) (string `)`) expr <|> number in - let term = factor |> some-chain-left (mulop <|> divop) in - let expr = term |> some-chain-left (addop <|> subop) in - expr - )) - in - `12/2/2` |> run expr |> Result.map (Fn.compose Debug.log String.of-int) |> Fn.ignore before - `1+2*4-12/2/2+4` |> run expr |> Result.map (Fn.compose Debug.log String.of-int) |> Fn.ignore in let () = open Parser in diff --git a/test/main.test.saty b/test/main.test.saty index 7830ad6..d9a3fc7 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -9,17 +9,19 @@ @import: array.test @import: int.test @import: list.test +@import: parser.test @import: ref.test @import: regex.test @import: string.test open Test in describe `base` [ - ref-test-cases; - string-test-cases; - list-test-cases; array-test-cases; - regex-test-cases; int-test-cases; + list-test-cases; + parser-test-cases; + ref-test-cases; + regex-test-cases; + string-test-cases; ] |> run diff --git a/test/parser.test.satyg b/test/parser.test.satyg new file mode 100644 index 0000000..44ddd64 --- /dev/null +++ b/test/parser.test.satyg @@ -0,0 +1,52 @@ +@require: test/test +@require: test/expect + +@import: ../src/result +@import: ../src/parser + +let parser-test-cases = open Test in + let is-ok-with eq a r = + Result.is-ok r + && Eq.equal eq a (Result.unwrap r) in + describe `Parser module` [ + it `parse many a` (fun () -> ( + open Parser in + `aaa` |> StringParser.run ( + many (StringParser.char (Char.make `a`))) + |> is-ok-with (List.eq Char.eq) [Char.make `a`; Char.make `a`; Char.make `a`] + |> Expect.is-true + )); + it `parse arithmetic expresisons` (fun () -> ( + open Parser in + open StringParser in + let op name f = string name >> ret f in + let addop = op `+` Int.add in + let subop = op `-` Int.sub in + let mulop = op `*` Int.mul in + let divop = op `/` Int.div in + let number = some digit >>= (fun cs -> ret (Int.of-string (String.of-list cs))) in + let expr = fix (fun expr -> ( + let factor = between (string `(`) (string `)`) expr <|> number in + let term = factor |> some-chain-left (mulop <|> divop) in + let expr = term |> some-chain-left (addop <|> subop) in + expr + )) + in + (`12/2/2` |> run expr + |> is-ok-with Int.eq 3) + && (`1+2*4-12/2/2+4` |> run expr + |> is-ok-with Int.eq 10) + |> Expect.is-true + )); + it `parse with alt` (fun () -> ( + open Parser in + open StringParser in + let p = + (label `expected 'foo'` (string `foo`)) + <|> (string `bar`) + in + (`bar` |> run p + |> is-ok-with String.eq `bar`) + |> Expect.is-true + )) + ] From ce759347ff8f7ed095c8b48f6e3f81fead8eff50 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Sun, 3 Mar 2024 14:07:30 +0900 Subject: [PATCH 21/39] GH-142: Add tests of Lexer This commit splits Lexer from typeset/code2.satyh for testability. --- __test__/satysrc/generic.saty | 25 ------------------------- src/lexer.satyg | 32 ++++++++++++++++++++++++++++++++ src/typeset/code2.satyh | 34 ++-------------------------------- test/lexer.test.satyg | 28 ++++++++++++++++++++++++++++ test/main.test.saty | 2 ++ 5 files changed, 64 insertions(+), 57 deletions(-) create mode 100644 src/lexer.satyg create mode 100644 test/lexer.test.satyg diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index 07a1ae3..9e359f8 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -37,31 +37,6 @@ @import: ../../src/tree-map @import: ../../src/big-int -let () = Debug.log `==== Parser ====` in - -let () = - open Parser in - open StringParser in - let p = - (label `expected 'foo'` (string `foo`)) - <|> (string `bar`) - in - `bar` |> run p |> Result.map Debug.log |> Result.map-err (fun errs -> ( - match errs with - | [] -> Debug.log `(something is wrong)` - | err :: _ -> Debug.log err#desc - )) |> Fn.ignore -in - -let () = Debug.log `==== Lexer ====` in -let rules = [ - (| kind = `identifier`; regexp = seq alpha (many (alt alpha (alt digit (char (Char.make `-`))))) |); - (| kind = `whitespace`; regexp = spaces |); -] in -let (Some tokens) = Lexer.lex rules `abc defg hijklMNL op123 ` in -let () = tokens |> List.iter (fun tk -> (Debug.log (`(| kind = `# ^ tk#kind ^ `, data = "`# ^ tk#data ^ `" |)`))) in - - let () = Debug.log `==== Map ====` in let m = Map.of-list [(1, `a`); (2, `b`); (3, `c`)] in let option-force (Some v) = v in diff --git a/src/lexer.satyg b/src/lexer.satyg new file mode 100644 index 0000000..7528036 --- /dev/null +++ b/src/lexer.satyg @@ -0,0 +1,32 @@ +@import: regexp +@import: string + +% % usage: +% let rules = [ +% (| kind = `identifier`; regexp = seq alpha (many (alt alpha (alt digit (char `-`)))) |); +% (| kind = `whitespace`; regexp = spaces |); +% ] in +% let (Some tokens) = Lexer.lex rules `abc defg hijklMNL op123 ` +% tokens |> List.iter (fun tk -> (Debug.log (`(| kind = `# ^ tk#kind ^ `, data = "`# ^ tk#data ^ `" |)`))) + +module Lexer : sig + val lex : ((| kind : string; regexp : RegExp.t |)) list -> string -> (((| kind : string; data : string |)) list) option +end = struct + + let lex rules src = + let len = String.length src in + let-rec loop i acc = + if i == len + then Some (List.reverse acc) + else + let s = src |> String.sub i (len - i) in + let-rec iter rules = match rules with + | [] -> None + | (r :: rules) -> let (m :: _) = RegExp.exec (RegExp.seq RegExp.bof r#regexp) s in + (match m with + | None -> iter rules + | (Some (_, m)) -> loop (i + String.length m) ((| kind = r#kind; data = m |) :: acc)) in + iter rules in + loop 0 [] + +end diff --git a/src/typeset/code2.satyh b/src/typeset/code2.satyh index 397089d..95c620c 100644 --- a/src/typeset/code2.satyh +++ b/src/typeset/code2.satyh @@ -3,40 +3,10 @@ @require: gr @require: vdecoset @require: list -@import: ../string -@import: ../regexp @import: ../debug @import: ../inline - -% % usage: -% let rules = [ -% (| kind = `identifier`; regexp = seq alpha (many (alt alpha (alt digit (char `-`)))) |); -% (| kind = `whitespace`; regexp = spaces |); -% ] in -% let (Some tokens) = Lexer.lex rules `abc defg hijklMNL op123 ` -% tokens |> List.iter (fun tk -> (Debug.log (`(| kind = `# ^ tk#kind ^ `, data = "`# ^ tk#data ^ `" |)`))) - -module Lexer : sig - val lex : ((| kind : string; regexp : RegExp.t |)) list -> string -> (((| kind : string; data : string |)) list) option -end = struct - - let lex rules src = - let len = String.length src in - let-rec loop i acc = - if i == len - then Some (List.reverse acc) - else - let s = src |> String.sub i (len - i) in - let-rec iter rules = match rules with - | [] -> None - | (r :: rules) -> let (m :: _) = RegExp.exec (RegExp.seq RegExp.bof r#regexp) s in - (match m with - | None -> iter rules - | (Some (_, m)) -> loop (i + String.length m) ((| kind = r#kind; data = m |) :: acc)) in - iter rules in - loop 0 [] - -end +@import: ../lexer +@import: ../regexp type syntax-def = (|groups : ((|color : color; keywords : string list|)) list; ident-regexp : RegExp.t|) diff --git a/test/lexer.test.satyg b/test/lexer.test.satyg new file mode 100644 index 0000000..452af2f --- /dev/null +++ b/test/lexer.test.satyg @@ -0,0 +1,28 @@ +@require: test/test +@require: test/expect + +@import: ../src/lexer +@import: ../src/result + +let lexer-test-cases = open Test in + let streq = Eq.equal String.eq in + let eq-token = Eq.make (fun a b -> (string-same a#kind b#kind) && (string-same a#data b#data)) in + describe `Lexer module` [ + it `tokenize string` (fun () -> ( + open RegExp in + let rules = [ + (| kind = `identifier`; regexp = seq alpha (many (alt alpha (alt digit (char (Char.make `-`))))) |); + (| kind = `whitespace`; regexp = spaces |); + ] in + let (Some tokens) = Lexer.lex rules `abc defg hijklMNL op123 ` in + tokens |> Eq.equal (List.eq eq-token) [ + (| kind = `identifier`; data = `abc`|); + (| kind = `whitespace`; data = #` `# |); + (| kind = `identifier`; data = `defg` |); + (| kind = `whitespace`; data = #` `# |); + (| kind = `identifier`; data = `hijklMNL` |); + (| kind = `whitespace`; data = #` `# |); + (| kind = `identifier`; data = `op123` |) + ] |> Expect.is-true + )); + ] diff --git a/test/main.test.saty b/test/main.test.saty index d9a3fc7..fdce935 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -8,6 +8,7 @@ @import: array.test @import: int.test +@import: lexer.test @import: list.test @import: parser.test @import: ref.test @@ -18,6 +19,7 @@ open Test in describe `base` [ array-test-cases; int-test-cases; + lexer-test-cases; list-test-cases; parser-test-cases; ref-test-cases; From f8fd33977afaaeafea98372bfb2a3828e8af7e1c Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Mon, 4 Mar 2024 07:34:46 +0900 Subject: [PATCH 22/39] GH-142: Migrate tests of Map --- __test__/satysrc/generic.saty | 11 ----------- test/main.test.saty | 2 ++ test/map.test.satyg | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 test/map.test.satyg diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index 9e359f8..c4c357b 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -37,17 +37,6 @@ @import: ../../src/tree-map @import: ../../src/big-int -let () = Debug.log `==== Map ====` in -let m = Map.of-list [(1, `a`); (2, `b`); (3, `c`)] in -let option-force (Some v) = v in -let () = m |> Map.of- Int.eq 1 |> option-force |> Debug.log in -let () = m |> Map.of- Int.eq 2 |> option-force |> Debug.log in -let () = m |> Map.of- Int.eq 3 |> option-force |> Debug.log in -let m = m |> Map.bind 2 `d` in -let () = m |> Map.of- Int.eq 1 |> option-force |> Debug.log in -let () = m |> Map.of- Int.eq 2 |> option-force |> Debug.log in -let () = m |> Map.of- Int.eq 3 |> option-force |> Debug.log in - let _ = Color.of-css `#F5F5DC` in let _ = Color.of-css `beige` in diff --git a/test/main.test.saty b/test/main.test.saty index fdce935..f282920 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -10,6 +10,7 @@ @import: int.test @import: lexer.test @import: list.test +@import: map.test @import: parser.test @import: ref.test @import: regex.test @@ -21,6 +22,7 @@ describe `base` [ int-test-cases; lexer-test-cases; list-test-cases; + map-test-cases; parser-test-cases; ref-test-cases; regex-test-cases; diff --git a/test/map.test.satyg b/test/map.test.satyg new file mode 100644 index 0000000..f7b3ed3 --- /dev/null +++ b/test/map.test.satyg @@ -0,0 +1,31 @@ +@require: test/test +@require: test/expect + +@import: ../src/option-ext +@import: ../src/map +@import: ../src/string + +let map-test-cases = open Test in + let stroeq = Eq.equal (Option.eq String.eq) in + let m = Map.of-list [(1, `a`); (2, `b`); (3, `c`)] in + describe `Map module` [ + it `get corresponding value` (fun () -> ( + (m |> Map.of- Int.eq 1 + |> stroeq (Option.some `a`)) + && (m |> Map.of- Int.eq 2 + |> stroeq (Option.some `b`)) + && (m |> Map.of- Int.eq 3 + |> stroeq (Option.some `c`)) + |> Expect.is-true + )); + it `rebind mapping` (fun () -> ( + let m = m |> Map.bind 2 `d` in + (m |> Map.of- Int.eq 1 + |> stroeq (Option.some `a`)) + && (m |> Map.of- Int.eq 2 + |> stroeq (Option.some `d`)) + && (m |> Map.of- Int.eq 3 + |> stroeq (Option.some `c`)) + |> Expect.is-true + )); + ] From fda0b82674b31a3f6ec2f55bf277e98021b45a34 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Mon, 4 Mar 2024 07:45:12 +0900 Subject: [PATCH 23/39] GH-142: Migrate test cases of Color --- __test__/satysrc/generic.saty | 3 --- test/color.test.satyg | 16 ++++++++++++++++ test/main.test.saty | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 test/color.test.satyg diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index c4c357b..3b2fdff 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -37,9 +37,6 @@ @import: ../../src/tree-map @import: ../../src/big-int -let _ = Color.of-css `#F5F5DC` in -let _ = Color.of-css `beige` in - let () = Debug.log `==== Promise ====` in let p = Promise.delay ~(!!(&(let () = Debug.log `foo` in 1))) in let () = Debug.log `bar` in diff --git a/test/color.test.satyg b/test/color.test.satyg new file mode 100644 index 0000000..4b83891 --- /dev/null +++ b/test/color.test.satyg @@ -0,0 +1,16 @@ +@require: test/test +@require: test/expect + +@import: ../src/color-ext + +let color-test-cases = open Test in + describe `Color module` [ + it `parse hex notation successfully` (fun () -> ( + let _ = Color.of-css `#F5F5DC` in + Expect.always-pass + )); + it `parse names successfully` (fun () -> ( + let _ =Color.of-css `beige` in + Expect.always-pass + )); + ] diff --git a/test/main.test.saty b/test/main.test.saty index f282920..af679dc 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -7,6 +7,7 @@ @import: ../src/string @import: array.test +@import: color.test @import: int.test @import: lexer.test @import: list.test @@ -19,6 +20,7 @@ open Test in describe `base` [ array-test-cases; + color-test-cases; int-test-cases; lexer-test-cases; list-test-cases; From 328585f0971b1c49fb016c9bec9084af28f1454f Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Mon, 4 Mar 2024 08:25:15 +0900 Subject: [PATCH 24/39] GH-142: Migrate test cases of Promise --- __test__/satysrc/generic.saty | 10 ---------- test/main.test.saty | 2 ++ test/promise.test.satyg | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 test/promise.test.satyg diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index 3b2fdff..38da84d 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -37,16 +37,6 @@ @import: ../../src/tree-map @import: ../../src/big-int -let () = Debug.log `==== Promise ====` in -let p = Promise.delay ~(!!(&(let () = Debug.log `foo` in 1))) in -let () = Debug.log `bar` in -let _ = Promise.force p in -let _ = Promise.force p in -let p = Promise.delay ~(!!(&(let () = Debug.log `foobar` in 3.14))) in -let () = Debug.log `barbaz` in -let _ = Promise.force p in -let _ = Promise.force p in - let () = Debug.log `==== Float ====` in let p f = f |> String.of-float |> Debug.log in let () = p Float.pi in diff --git a/test/main.test.saty b/test/main.test.saty index af679dc..5ce72e1 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -13,6 +13,7 @@ @import: list.test @import: map.test @import: parser.test +@import: promise.test @import: ref.test @import: regex.test @import: string.test @@ -26,6 +27,7 @@ describe `base` [ list-test-cases; map-test-cases; parser-test-cases; + promise-test-cases; ref-test-cases; regex-test-cases; string-test-cases; diff --git a/test/promise.test.satyg b/test/promise.test.satyg new file mode 100644 index 0000000..7b0a12f --- /dev/null +++ b/test/promise.test.satyg @@ -0,0 +1,20 @@ +@require: test/test +@require: test/expect + +@import: ../src/base0 +@import: ../src/ref +@import: ../src/promise + +let promise-test-cases = open Test in + describe `Promise module` [ + it `evaluate lazily` (fun () -> ( + let r = Ref.make 0 in + let p = Promise.delay ~(!!(&(let () = r |> Ref.inc in 1))) in + Ref.get r == 0 + && (let _ = Promise.force p in + Ref.get r == 1 + && (let _ = Promise.force p in + Ref.get r == 1)) + |> Expect.is-true + )); + ] From 7b27027cd8d4b1ec0ede300b29926867f402f229 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Mon, 4 Mar 2024 12:22:54 +0900 Subject: [PATCH 25/39] GH-142: Migrate test cases of Float --- __test__/satysrc/generic.saty | 51 -------------- test/float.test.satyg | 124 ++++++++++++++++++++++++++++++++++ test/main.test.saty | 2 + 3 files changed, 126 insertions(+), 51 deletions(-) create mode 100644 test/float.test.satyg diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index 38da84d..d59abf4 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -37,57 +37,6 @@ @import: ../../src/tree-map @import: ../../src/big-int -let () = Debug.log `==== Float ====` in -let p f = f |> String.of-float |> Debug.log in -let () = p Float.pi in -let () = p Float.e in -let l = [Float.inf; Float.ninf; Float.nan; 0.0; Float.neg 0.0; 1.0] in -let _ = l |> List.iter (fun a -> - l |> List.iter (fun b -> - Debug.log (String.of-float a ^ #` == `# ^ String.of-float b ^ #` = `# ^ String.of-bool Float.(a == b)) - ) -) in -let () = p (1.0 /. 0.0) in -let () = p (1.0 /. Float.neg 0.0) in -let () = p (0.0 /. 0.0) in -let () = p (Float.exp Float.pi) in -let () = p (Float.log Float.pi) in -let () = p (Float.pi |> Float.pow Float.pi) in -let () = p (2.1 |> Float.pow 54.0) in -let () = p (Float.sqrt 2.0) in -let () = p (Float.log10 Float.pi) in -let dbl-min = Stream.nat |> Stream.take 1022 |> Fn.flip Stream.fold 1.0 (fun f _ -> f /. 2.0) in -let () = p dbl-min in -let half-dbl-min = dbl-min /. 2.0 in -let () = p half-dbl-min in -let l = l |> List.append [dbl-min; half-dbl-min] in -let p-bool b = b |> String.of-bool |> Debug.log in -let () = l |> List.iter (fun f -> p-bool (Float.is-zero f)) in -let () = l |> List.iter (fun f -> p-bool (Float.is-inf f)) in -let () = l |> List.iter (fun f -> p-bool (Float.is-nan f)) in -let () = l |> List.iter (fun f -> p-bool (Float.is-normal f)) in -let () = l |> List.iter (fun f -> p-bool (Float.is-subnormal f)) in -let l = [2.3; 3.8; 5.5; Float.neg 2.3; Float.neg 3.8; Float.neg 5.5; 6.0] in -let () = l |> List.iter (fun a -> (p (Float.round a))) in -let () = l |> List.iter (fun a -> (p (Float.floor a))) in -let () = l |> List.iter (fun a -> (p (Float.ceil a))) in -let () = l |> List.iter (fun a -> (p (Float.truncate a))) in -% virtually testing exp2i -let () = [-1073; -1074; -1075; 1022; 1023; 1024] |> List.iter (fun a -> (p (1.0 |> Float.ldexp a))) in -let p-opt o = - let s = - match o with - | None -> `None` - | Some(i) -> `Some(` ^ Float.to-string i ^ `)` - in - Debug.log s -in -let () = p-opt(`123.45` |> Float.of-string-opt) in -let () = p-opt(`-123.45` |> Float.of-string-opt) in -let () = p-opt(`123.0` |> Float.of-string-opt) in -let () = p-opt(`0.111` |> Float.of-string-opt) in -let () = p-opt(`0.1a11` |> Float.of-string-opt) in - let () = Debug.log `==== Bool ====` in let p b = b |> Bool.to-string |> Debug.log in let p-opt o = diff --git a/test/float.test.satyg b/test/float.test.satyg new file mode 100644 index 0000000..f551cc9 --- /dev/null +++ b/test/float.test.satyg @@ -0,0 +1,124 @@ +@require: test/test +@require: test/expect + +@import: ../src/bool +@import: ../src/eq +@import: ../src/float +@import: ../src/stream +@import: ../src/string + +let float-test-cases = open Test in + let streq = Eq.equal String.eq in + let strleq = Eq.equal (List.eq String.eq) in + let boolleq = Eq.equal (List.eq Bool.eq) in + let flleq = Eq.equal (List.eq Float.eq) in + let floleq = Eq.equal (List.eq (Option.eq Float.eq)) in + % smallest normal value + let dbl-min = Stream.nat + |> Stream.take 1022 + |> Fn.flip Stream.fold 1.0 (fun f _ -> f /. 2.0) in + % subnormal value + let half-dbl-min = dbl-min /. 2.0 in + describe `Float module` [ + it `provide constants` (fun () -> ( + (String.of-float Float.pi + |> streq `3.14159265359`) + && (String.of-float Float.e + |> streq `2.71828182846`) + |> Expect.is-true + )); + it `check equality of special values` (fun () -> ( + Float.( + inf == inf + && ninf == ninf + && not (nan == nan) + && not (nan == Float.neg nan) + && 0.0 == 0.0 + && 0.0 == Float.neg 0.0 + ) |> Expect.is-true + )); + it `calculate division with zero` (fun () -> ( + Float.( + 1.0 /. 0.0 == inf + && 1.0 /. (neg 0.0) == ninf + && (0.0 /. 0.0 |> is-nan) + ) |> Expect.is-true + )); + it `calculuate exp, log, pow, sqrt, log10` (fun () -> ( + (Float.exp Float.pi + |> String.of-float + |> streq `23.1406926328`) + && (Float.log Float.pi + |> String.of-float + |> streq `1.14472988585`) + && (Float.pi |> Float.pow Float.pi + |> String.of-float + |> streq `36.4621596072`) + && (2.1 |> Float.pow 54.0 + |> String.of-float + |> streq `2.51097226443e+17`) + && (Float.sqrt 2.0 + |> String.of-float + |> streq `1.41421356237`) + && (Float.log10 Float.pi + |> String.of-float + |> streq `0.497149872694`) + |> Expect.is-true + )); + it `prnit smallest normal value and subnormal value` (fun () -> ( + (dbl-min |> String.of-float |> streq `2.22507385851e-308`) + && (half-dbl-min |> String.of-float |> streq `1.11253692925e-308`) + |> Expect.is-true + )); + it `check props of special values` (fun () -> ( + let props f = [ + Float.is-zero f; + Float.is-inf f; + Float.is-nan f; + Float.is-normal f; + Float.is-subnormal f; + ] in + (props Float.inf |> boolleq [false; true; false; false; false]) + && (props Float.ninf |> boolleq [false; true; false; false; false]) + && (props Float.nan |> boolleq [false; false; true; false; false]) + && (props 0.0 |> boolleq [true; false; false; false; false]) + && (props (Float.neg 0.0) |> boolleq [true; false; false; false; false]) + && (props 1.0 |> boolleq [false; false; false; true; false]) + && (props dbl-min |> boolleq [false; false; false; true; false]) + && (props half-dbl-min |> boolleq [false; false; false; false; true ]) + |> Expect.is-true + )); + it `round, floor, ceil, truncate` (fun () -> ( + open Float in + let l = [2.3; 3.8; 5.5; neg 2.3; neg 3.8; neg 5.5; 6.0] in + (l |> List.map round + |> flleq [2.; 4.; 6.; neg 2.; neg 4.; neg 6.; 6.]) + && (l |> List.map floor + |> flleq [2.; 3.; 5.; neg 3.; neg 4.; neg 6.; 6.]) + && (l |> List.map ceil + |> flleq [3.; 4.; 6.; neg 2.; neg 3.; neg 5.; 6.]) + && (l |> List.map truncate + |> flleq [2.; 3.; 5.; neg 2.; neg 3.; neg 5.; 6.]) + |> Expect.is-true + )); + it `virtually test exp2i` (fun () -> ( + [-1073; -1074; -1075; 1022; 1023; 1024] + |> List.map (fun a -> 1.0 |> Float.ldexp a) + |> List.map String.of-float + |> strleq [ + `9.88131291682e-324`; + `4.94065645841e-324`; + `0.`; + `4.49423283716e+307`; + `8.98846567431e+307`; + `inf`; + ] + |> Expect.is-true + )); + it `parse float` (fun () -> ( + [`123.45`; `-123.45`; `123.0`; `0.111`; `0.1a11`] + |> List.map Float.of-string-opt + |> floleq Option.([some 123.45; some (Float.neg 123.45); some 123.0; some 0.111; none]) + |> Expect.is-true + )) + ] diff --git a/test/main.test.saty b/test/main.test.saty index 5ce72e1..033ee64 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -8,6 +8,7 @@ @import: array.test @import: color.test +@import: float.test @import: int.test @import: lexer.test @import: list.test @@ -22,6 +23,7 @@ open Test in describe `base` [ array-test-cases; color-test-cases; + float-test-cases; int-test-cases; lexer-test-cases; list-test-cases; From f2c674ad97ccd50d252fafa1f0021feefc04a7ec Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Mon, 4 Mar 2024 12:38:32 +0900 Subject: [PATCH 26/39] GH-142: Migrate test cases of Stream --- __test__/satysrc/generic.saty | 5 ----- test/main.test.saty | 2 ++ test/stream.test.satyg | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 test/stream.test.satyg diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index d59abf4..ec385b1 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -56,11 +56,6 @@ let () = p-opt(`false` |> Bool.of-string-opt) in let () = p-opt(`true` |> Bool.of-string-opt) in let () = p-opt(`hoge` |> Bool.of-string-opt) in -let () = Debug.log `==== Stream ====` in -let () = Stream.fib |> Stream.take 30 |> Stream.to-list |> List.iter (fun x -> Debug.log <| String.of-int x) in -let () = Stream.nat |> Stream.take 5 |> Stream.to-list |> List.iter (fun x -> Debug.log <| String.of-int x) -in - let () = Debug.log `==== Fn ====` in let () = 0 |> Fn.fix (fun loop n -> ( if n >= 10 then diff --git a/test/main.test.saty b/test/main.test.saty index 033ee64..9366ed4 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -17,6 +17,7 @@ @import: promise.test @import: ref.test @import: regex.test +@import: stream.test @import: string.test open Test in @@ -32,6 +33,7 @@ describe `base` [ promise-test-cases; ref-test-cases; regex-test-cases; + stream-test-cases; string-test-cases; ] |> run diff --git a/test/stream.test.satyg b/test/stream.test.satyg new file mode 100644 index 0000000..e907f68 --- /dev/null +++ b/test/stream.test.satyg @@ -0,0 +1,22 @@ +@require: test/test +@require: test/expect + +@import: ../src/eq +@import: ../src/int +@import: ../src/list-ext +@import: ../src/stream + +let stream-test-cases = open Test in + let intleq = Eq.equal (List.eq Int.eq) in + describe `Stream module` [ + it `nat` (fun () -> ( + Stream.nat |> Stream.take 5 |> Stream.to-list + |> intleq [0; 1; 2; 3; 4] + |> Expect.is-true + )); + it `fib` (fun () -> ( + Stream.fib |> Stream.take 15 |> Stream.to-list + |> intleq [1; 1; 2; 3; 5; 8; 13; 21; 34; 55; 89; 144; 233; 377; 610] + |> Expect.is-true + )); + ] From 6d323f9157db8e3557684079edd3233170ff85ef Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Mon, 4 Mar 2024 12:50:34 +0900 Subject: [PATCH 27/39] GH-142: Migrate test cases of Bool --- __test__/satysrc/generic.saty | 19 ------------------- test/bool.test.satyg | 34 ++++++++++++++++++++++++++++++++++ test/main.test.saty | 2 ++ 3 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 test/bool.test.satyg diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index ec385b1..93e7718 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -37,25 +37,6 @@ @import: ../../src/tree-map @import: ../../src/big-int -let () = Debug.log `==== Bool ====` in -let p b = b |> Bool.to-string |> Debug.log in -let p-opt o = - let s = - match o with - | None -> `None` - | Some(i) -> `Some(` ^ Bool.to-string i ^ `)` - in - Debug.log s -in -let () = p Bool.max-value in -let () = p Bool.min-value in -let () = p-opt(0 |> Bool.of-int-opt) in -let () = p-opt(1 |> Bool.of-int-opt) in -let () = p-opt(2 |> Bool.of-int-opt) in -let () = p-opt(`false` |> Bool.of-string-opt) in -let () = p-opt(`true` |> Bool.of-string-opt) in -let () = p-opt(`hoge` |> Bool.of-string-opt) in - let () = Debug.log `==== Fn ====` in let () = 0 |> Fn.fix (fun loop n -> ( if n >= 10 then diff --git a/test/bool.test.satyg b/test/bool.test.satyg new file mode 100644 index 0000000..6e46709 --- /dev/null +++ b/test/bool.test.satyg @@ -0,0 +1,34 @@ +@require: test/test +@require: test/expect + +@import: ../src/eq +@import: ../src/int +@import: ../src/bool +@import: ../src/option-ext + +let bool-test-cases = open Test in + let booleq = Eq.equal Bool.eq in + let boololeq = Eq.equal (List.eq (Option.eq Bool.eq)) in + let stroeq = Eq.equal (Option.eq Bool.eq) in + describe `Bool module` [ + it `have max and min` (fun () -> ( + booleq Bool.max-value true + && booleq Bool.min-value false + |> Expect.is-true + )); + it `coerce int value to bool` (fun () -> ( + [0; 1; 2] + |> List.map Bool.of-int-opt + |> boololeq Option.([some false; some true; none]) + |> Expect.is-true + )); + it `parse bool` (fun () -> ( + [`false`; `true`; `hoge`] + |> List.map Bool.of-string-opt + |> boololeq Option.([ + some false; + some true; + none; + ]) |> Expect.is-true + )) + ] diff --git a/test/main.test.saty b/test/main.test.saty index 9366ed4..7e223a2 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -7,6 +7,7 @@ @import: ../src/string @import: array.test +@import: bool.test @import: color.test @import: float.test @import: int.test @@ -23,6 +24,7 @@ open Test in describe `base` [ array-test-cases; + bool-test-cases; color-test-cases; float-test-cases; int-test-cases; From 61cab625aa915942256738d499b1e7929f69371a Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Mon, 4 Mar 2024 13:18:32 +0900 Subject: [PATCH 28/39] GH-142: Migrate test cases of Fn --- __test__/satysrc/generic.saty | 10 ---------- test/fn.test.satyg | 17 +++++++++++++++++ test/main.test.saty | 2 ++ 3 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 test/fn.test.satyg diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index 93e7718..8345608 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -37,16 +37,6 @@ @import: ../../src/tree-map @import: ../../src/big-int -let () = Debug.log `==== Fn ====` in -let () = 0 |> Fn.fix (fun loop n -> ( - if n >= 10 then - Debug.log `done` - else - Debug.log (String.of-int n) before - loop (n + 1) -)) -in - let () = Debug.log `==== TreeSet ====` in % REMARK: % This test relies on the fact that the order of elements of a result from TreeSet.to-list is diff --git a/test/fn.test.satyg b/test/fn.test.satyg new file mode 100644 index 0000000..6b48637 --- /dev/null +++ b/test/fn.test.satyg @@ -0,0 +1,17 @@ +@require: test/test +@require: test/expect + +@import: ../src/fn + +let fn-test-cases = open Test in + describe `Fn module` [ + it `make recursive function with fix` (fun x -> ( + Fn.fix (fun loop n -> ( + if n >= 10 then + 0 + else + n + loop (n + 1))) 0 + |> (==) 45 + |> Expect.is-true + )) + ] diff --git a/test/main.test.saty b/test/main.test.saty index 7e223a2..5967256 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -10,6 +10,7 @@ @import: bool.test @import: color.test @import: float.test +@import: fn.test @import: int.test @import: lexer.test @import: list.test @@ -27,6 +28,7 @@ describe `base` [ bool-test-cases; color-test-cases; float-test-cases; + fn-test-cases; int-test-cases; lexer-test-cases; list-test-cases; From b2a171ceef2f3827b1920b240fb4bbf2000ad6f2 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Mon, 4 Mar 2024 16:25:34 +0900 Subject: [PATCH 29/39] GH-142: Migrate tests of TreeSet --- __test__/satysrc/generic.saty | 67 -------------------- test/main.test.saty | 2 + test/treeset.test.satyg | 111 ++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 67 deletions(-) create mode 100644 test/treeset.test.satyg diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index 8345608..58ba2bd 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -37,73 +37,6 @@ @import: ../../src/tree-map @import: ../../src/big-int -let () = Debug.log `==== TreeSet ====` in -% REMARK: -% This test relies on the fact that the order of elements of a result from TreeSet.to-list is -% level-order (BFS). If the implementation is changed, the following tests have to be updated. -let p s = s |> TreeSet.to-list |> List.map String.of-int |> List.intersperse `,` |> (fun l -> String.concat l) |> Debug.log in -let s = TreeSet.empty in -let () = p s in -let s = TreeSet.of-list Int.ord [3;2;3;1] in -let () = p s in -let () = Debug.log `check rotations:` in -% right left rotation -let s = [1;3;2] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty in -let () = p s in -% right left rotation -let s = [3;1;2] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty in -let () = p s in -% left rotation -let s = [3;2;1] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty in -let () = p s in -% right rotation -let s = [1;2;3] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty in -let () = p s in -% 16 -% 8 24 -% 4 12 20 28 -let s = [16;8;24;4;12;20;28] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty in -let () = p s in -% right rotation -let t = [3;2;1;0;-1] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) s in -let () = p t in -% left rotation -let t = [29;30;31;32;33] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) s in -let () = p t in -% right left rotation -let t = [9;15;10;11] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) s in -let () = p t in -% left right rotation -let t = [23;17;22;19] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) s in -let () = p t in -let () = Debug.log `check size after insertion:` in -let () = TreeSet.size TreeSet.empty |> String.of-int |> Debug.log in -let () = TreeSet.size s |> String.of-int |> Debug.log in -let t = s |> TreeSet.insert Int.ord 16 in -let () = TreeSet.size t |> String.of-int |> Debug.log in -let t = s |> TreeSet.insert Int.ord 24 in -let () = TreeSet.size t |> String.of-int |> Debug.log in -let t = s |> TreeSet.insert Int.ord 20 in -let () = TreeSet.size t |> String.of-int |> Debug.log in -let () = Debug.log `check remove:` in -let t = TreeSet.remove Int.ord 16 s in -let () = p t in -let t = TreeSet.remove Int.ord 28 t in -let () = p t in -let t = TreeSet.remove Int.ord 24 t in -let () = p t in -let () = TreeSet.size t |> String.of-int |> Debug.log in -let t = TreeSet.remove Int.ord 10 t in -let () = p t in -let () = TreeSet.size t |> String.of-int |> Debug.log in -% See https://github.com/nyuichi/satysfi-base/pull/140#discussion_r550355160 -let t = [9;4;11;2;6;10;13;1;3;5;8;12;0;7] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty in -let t = TreeSet.remove Int.ord 13 t in -let () = p t in -let () = Debug.log `check get:` in -let () = s |> TreeSet.get Int.ord 20 |> Option.unwrap-or (-1) |> String.of-int |> Debug.log in -let () = s |> TreeSet.get Int.ord 23 |> Option.unwrap-or (-1) |> String.of-int |> Debug.log in - let () = Debug.log `==== TreeMap ====` in let m = TreeMap.of-list String.ord [(`apple`, 1); (`orange`, 3); (`pear`, 2)] in let () = Debug.log (String.of-int (m |> TreeMap.get String.ord `orange` |> Option.unwrap)) in diff --git a/test/main.test.saty b/test/main.test.saty index 5967256..08b70f8 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -21,6 +21,7 @@ @import: regex.test @import: stream.test @import: string.test +@import: treeset.test open Test in describe `base` [ @@ -39,5 +40,6 @@ describe `base` [ regex-test-cases; stream-test-cases; string-test-cases; + tree-set-test-cases; ] |> run diff --git a/test/treeset.test.satyg b/test/treeset.test.satyg new file mode 100644 index 0000000..dc3f86e --- /dev/null +++ b/test/treeset.test.satyg @@ -0,0 +1,111 @@ +@require: test/test +@require: test/expect + +@import: ../src/int +@import: ../src/list-ext +@import: ../src/tree-set + +let tree-set-test-cases = open Test in + let intleq = Eq.equal (List.eq Int.eq) in + describe `TreeSet module` [ + % REMARK: + % This test relies on the fact that the order of elements of a result from TreeSet.to-list is + % level-order (BFS). If the implementation is changed, the following tests have to be updated. + it `make an empty set` (fun _ -> ( + TreeSet.empty |> TreeSet.to-list |> intleq [] + |> Expect.is-true + )); + it `make a set from a given list` (fun () -> ( + TreeSet.of-list Int.ord [3;2;3;1] |> TreeSet.to-list + |> intleq [2;1;3] + |> Expect.is-true + )); + it `check rotations 1` (fun () -> ( + % right left rotation + ([1; 3; 2] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty + |> TreeSet.to-list + |> intleq [2; 1; 3]) + % right left rotation + && ([3; 1; 2] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty + |> TreeSet.to-list + |> intleq [2; 1; 3]) + % left rotation + && ([3; 2; 1] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty + |> TreeSet.to-list + |> intleq [2; 1; 3]) + % right rotation + && ([3; 2; 1] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty + |> TreeSet.to-list + |> intleq [2; 1; 3]) + |> Expect.is-true + )); + it `check rotations 2` (fun () -> ( + % 16 + % 8 24 + % 4 12 20 28 + let s = ([16; 8; 24; 4; 12; 20; 28] + |> List.fold-left (fun t x -> TreeSet.insert Int.ord x t) TreeSet.empty) in + ((s |> TreeSet.to-list + |> intleq [16; 8; 24; 4; 12; 20; 28])) + % right rotation + && ([3; 2; 1; 0; -1] |> List.fold-left (fun t x -> TreeSet.insert Int.ord x t) s + |> TreeSet.to-list + |> intleq [3; 1; 16; 0; 2; 8; 24; -1; 4; 12; 20; 28]) + % left rotation + && ([29; 30; 31; 32; 33] |> List.fold-left (fun t x -> TreeSet.insert Int.ord x t) s + |> TreeSet.to-list + |> intleq [29; 16; 31; 8; 24; 30; 32; 4; 12; 20; 28; 33]) + % right left rotation + && ([9; 15; 10; 11] |> List.fold-left (fun t x -> TreeSet.insert Int.ord x t) s + |> TreeSet.to-list + |> intleq [12; 9; 16; 8; 10; 15; 24; 4; 11; 20; 28]) + % left right rotation + && ([23; 17; 22; 19] |> List.fold-left (fun t x -> TreeSet.insert Int.ord x t) s + |> TreeSet.to-list + |> intleq [20; 16; 23; 8; 17; 22; 24; 4; 12; 19; 28])) + |> Expect.is-true + ); + it `check size after insertion` (fun () -> ( + TreeSet.size TreeSet.empty == 0 + && (let s = [16;8;24;4;12;20;28] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty in + TreeSet.size s == 7 + && (s |> TreeSet.insert Int.ord 16 + |> TreeSet.size + |> (==) 7) + && (s |> TreeSet.insert Int.ord 24 + |> TreeSet.size + |> (==) 7) + && (s |> TreeSet.insert Int.ord 20 + |> TreeSet.size + |> (==) 7) + ) |> Expect.is-true + )); + it `check remove 1` (fun () -> ( + let s1 = [16; 8; 24; 4; 12; 20; 28] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty in + let s2 = TreeSet.remove Int.ord 16 s1 in + let s3 = TreeSet.remove Int.ord 28 s2 in + let s4 = TreeSet.remove Int.ord 24 s3 in + let s5 = TreeSet.remove Int.ord 10 s4 in + (s2 |> TreeSet.to-list |> intleq [20; 8; 24; 4; 12; 28]) + && (s3 |> TreeSet.to-list |> intleq [20; 8; 24; 4; 12]) + && (s4 |> TreeSet.to-list |> intleq [8; 4; 20; 12]) + && (s4 |> TreeSet.size |> (==) 4) + && (s5 |> TreeSet.to-list |> intleq [8; 4; 20; 12]) + && (s5 |> TreeSet.size |> (==) 4) + |> Expect.is-true + )); + % See https://github.com/nyuichi/satysfi-base/pull/140#discussion_r550355160 + it `check remove 2` (fun () -> ( + [9;4;11;2;6;10;13;1;3;5;8;12;0;7] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty + |> TreeSet.remove Int.ord 13 + |> TreeSet.to-list + |> intleq [4; 2; 9; 1; 3; 6; 11; 0; 5; 8; 10; 12; 7] + |> Expect.is-true + )); + it `check get` (fun () -> ( + let s = [16; 8; 24; 4; 12; 20; 28] |> List.fold-left (fun s x -> TreeSet.insert Int.ord x s) TreeSet.empty in + (s |> TreeSet.get Int.ord 20 |> Option.unwrap-or (-1) |> (==) 20) + && (s |> TreeSet.get Int.ord 23 |> Option.unwrap-or (-1) |> (==) (-1)) + |> Expect.is-true + )) + ] From 9c5717f4872a1c2b60dc98ffffc949e406e199c6 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Mon, 4 Mar 2024 16:39:44 +0900 Subject: [PATCH 30/39] GH-142: Migrate tests of TreeMap --- __test__/satysrc/generic.saty | 8 -------- test/main.test.saty | 2 ++ test/treemap.test.satyg | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 test/treemap.test.satyg diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty index 58ba2bd..b7d0008 100644 --- a/__test__/satysrc/generic.saty +++ b/__test__/satysrc/generic.saty @@ -37,14 +37,6 @@ @import: ../../src/tree-map @import: ../../src/big-int -let () = Debug.log `==== TreeMap ====` in -let m = TreeMap.of-list String.ord [(`apple`, 1); (`orange`, 3); (`pear`, 2)] in -let () = Debug.log (String.of-int (m |> TreeMap.get String.ord `orange` |> Option.unwrap)) in -let () = Debug.log (String.of-int (m |> TreeMap.get String.ord `pear` |> Option.unwrap)) in -let m = m |> TreeMap.insert String.ord `pear` 4 in -let () = Debug.log (String.of-int (m |> TreeMap.get String.ord `orange` |> Option.unwrap)) in -let () = Debug.log (String.of-int (m |> TreeMap.get String.ord `pear` |> Option.unwrap)) in - let () = Debug.log `==== BigInt ====` in let p t = t |> BigInt.to-string |> Debug.log in let () = p (BigInt.of-string `42`) in diff --git a/test/main.test.saty b/test/main.test.saty index 08b70f8..953fee7 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -21,6 +21,7 @@ @import: regex.test @import: stream.test @import: string.test +@import: treemap.test @import: treeset.test open Test in @@ -40,6 +41,7 @@ describe `base` [ regex-test-cases; stream-test-cases; string-test-cases; + tree-map-test-cases; tree-set-test-cases; ] |> run diff --git a/test/treemap.test.satyg b/test/treemap.test.satyg new file mode 100644 index 0000000..2c24afd --- /dev/null +++ b/test/treemap.test.satyg @@ -0,0 +1,16 @@ +@require: test/test +@require: test/expect + +@import: ../src/option-ext +@import: ../src/tree-map + +let tree-map-test-cases = open Test in + let intoeq = Eq.equal (Option.eq Int.eq) in + describe `TreeMap module` [ + it `get mapping` (fun () -> ( + let m = TreeMap.of-list String.ord [(`apple`, 1); (`orange`, 3); (`pear`, 2)] in + (m |> TreeMap.get String.ord `orange` |> intoeq (Option.some 3)) + && (m |> TreeMap.get String.ord `pear` |> intoeq (Option.some 2)) + |> Expect.is-true + )) + ] From c0fc5eb7231455ceff2dfd37a3282ace24f1603a Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Tue, 5 Mar 2024 14:21:58 +0900 Subject: [PATCH 31/39] GH-142: Migrate tests of BigInt --- __test__/satysrc/generic.saty | 120 ---------------------------------- test/big-int.test.satyg | 99 ++++++++++++++++++++++++++++ test/main.test.saty | 2 + 3 files changed, 101 insertions(+), 120 deletions(-) delete mode 100644 __test__/satysrc/generic.saty create mode 100644 test/big-int.test.satyg diff --git a/__test__/satysrc/generic.saty b/__test__/satysrc/generic.saty deleted file mode 100644 index b7d0008..0000000 --- a/__test__/satysrc/generic.saty +++ /dev/null @@ -1,120 +0,0 @@ -@require: stdjareport -@require: list -@import: ../../src/base -@import: ../../src/base0 -@import: ../../src/base1 -@import: ../../src/ref -@import: ../../src/string -@import: ../../src/debug -@import: ../../src/array -@import: ../../src/regexp -@import: ../../src/list-ext -@import: ../../src/option-ext -@import: ../../src/typeset/code2 -@import: ../../src/parser -@import: ../../src/int -@import: ../../src/map -@import: ../../src/color-ext -@import: ../../src/promise -@import: ../../src/fn -@import: ../../src/float -@import: ../../src/length -@import: ../../src/set -@import: ../../src/tuple -@import: ../../src/graphics -@import: ../../src/path -@import: ../../src/typeset/math-ext -@import: ../../src/result -@import: ../../src/void -@import: ../../src/ord -@import: ../../src/eq -@import: ../../src/either -@import: ../../src/stream -@import: ../../src/pager -@import: ../../src/cross-ref -@import: ../../src/bool -@import: ../../src/tree-set -@import: ../../src/tree-map -@import: ../../src/big-int - -let () = Debug.log `==== BigInt ====` in -let p t = t |> BigInt.to-string |> Debug.log in -let () = p (BigInt.of-string `42`) in -let () = p (BigInt.of-string `-123`) in -let () = p (BigInt.of-string `-10`) in -let () = p BigInt.zero in -let () = p BigInt.one in -let () = p BigInt.minus-one in - -let () = BigInt.((BigInt.of-string `42`) < (BigInt.of-string `136`)) |> Bool.to-string |> Debug.log in -let () = BigInt.((BigInt.of-string `42`) <= (BigInt.of-string `136`)) |> Bool.to-string |> Debug.log in -let () = BigInt.((BigInt.of-string `42`) > (BigInt.of-string `136`)) |> Bool.to-string |> Debug.log in -let () = BigInt.((BigInt.of-string `42`) >= (BigInt.of-string `136`)) |> Bool.to-string |> Debug.log in -let () = BigInt.((BigInt.of-string `42`) == (BigInt.of-string `136`)) |> Bool.to-string |> Debug.log in -let () = BigInt.((BigInt.of-string `-42`) < (BigInt.of-string `-136`)) |> Bool.to-string |> Debug.log in - -let ord-to-string o = match o with | Lt -> `Lt` | Gt -> `Gt` | Eq -> `Eq` in -let p-ord n m = - Ord.compare BigInt.ord n m - |> ord-to-string - |> Debug.log -in -let () = p-ord (BigInt.of-string `123`) (BigInt.of-string `-456`) in -let () = p-ord (BigInt.of-string `-123`) (BigInt.of-string `456`) in -let () = p-ord (BigInt.of-string `333`) (BigInt.of-string `333`) in -let () = p-ord (BigInt.of-string `-333`) (BigInt.of-string `-333`) in -let () = p-ord (BigInt.of-string `1234`) (BigInt.of-string `432`) in -let () = p-ord (BigInt.of-string `432`) (BigInt.of-string `1234`) in -let () = p-ord (BigInt.of-string `-1234`) (BigInt.of-string `-432`) in -let () = p-ord (BigInt.of-string `-432`) (BigInt.of-string `-1234`) in -let () = p-ord (BigInt.of-string `332`) (BigInt.of-string `333`) in -let () = p-ord (BigInt.of-string `333`) (BigInt.of-string `332`) in -let () = p-ord (BigInt.of-string `-332`) (BigInt.of-string `-333`) in -let () = p-ord (BigInt.of-string `-333`) (BigInt.of-string `-332`) in - - - -let () = p (BigInt.add (BigInt.of-string `42`) (BigInt.of-string `39`)) in -let () = p (BigInt.add (BigInt.of-string `42`) (BigInt.of-string `-39`)) in -let () = p (BigInt.add (BigInt.of-string `-42`) (BigInt.of-string `39`)) in -let () = p (BigInt.add (BigInt.of-string `-42`) (BigInt.of-string `-39`)) in -let () = p (BigInt.add (BigInt.of-string `42`) (BigInt.of-string `45`)) in -let () = p (BigInt.add (BigInt.of-string `42`) (BigInt.of-string `-45`)) in -let () = p (BigInt.add (BigInt.of-string `-42`) (BigInt.of-string `45`)) in -let () = p (BigInt.add (BigInt.of-string `-42`) (BigInt.of-string `-45`)) in - -let () = p (BigInt.sub (BigInt.of-string `42`) (BigInt.of-string `39`)) in -let () = p (BigInt.sub (BigInt.of-string `42`) (BigInt.of-string `-39`)) in -let () = p (BigInt.sub (BigInt.of-string `-42`) (BigInt.of-string `39`)) in -let () = p (BigInt.sub (BigInt.of-string `-42`) (BigInt.of-string `-39`)) in -let () = p (BigInt.sub (BigInt.of-string `42`) (BigInt.of-string `45`)) in -let () = p (BigInt.sub (BigInt.of-string `42`) (BigInt.of-string `-45`)) in -let () = p (BigInt.sub (BigInt.of-string `-42`) (BigInt.of-string `45`)) in -let () = p (BigInt.sub (BigInt.of-string `-42`) (BigInt.of-string `-45`)) in - -let () = p (BigInt.mul (BigInt.of-string `157`) (BigInt.of-string `16`)) in -let () = p (BigInt.mul (BigInt.of-string `157`) (BigInt.of-string `-16`)) in -let () = p (BigInt.mul (BigInt.of-string `-157`) (BigInt.of-string `16`)) in -let () = p (BigInt.mul (BigInt.of-string `-157`) (BigInt.of-string `-16`)) in - -let () = p (BigInt.div (BigInt.of-string `12345`) (BigInt.of-string `43`)) in -let () = p (BigInt.mod- (BigInt.of-string `12345`) (BigInt.of-string `43`)) in -let () = p (BigInt.div (BigInt.of-string `1111111`) (BigInt.of-string `4649`)) in -let () = p (BigInt.mod- (BigInt.of-string `1111111`) (BigInt.of-string `4649`)) in -let () = p (BigInt.div (BigInt.of-string `-12345`) (BigInt.of-string `43`)) in -let () = p (BigInt.mod- (BigInt.of-string `-12345`) (BigInt.of-string `43`)) in -let () = p (BigInt.div (BigInt.of-string `12345`) (BigInt.of-string `-43`)) in -let () = p (BigInt.mod- (BigInt.of-string `12345`) (BigInt.of-string `-43`)) in -let () = p (BigInt.div (BigInt.of-string `-12345`) (BigInt.of-string `-43`)) in -let () = p (BigInt.mod- (BigInt.of-string `-12345`) (BigInt.of-string `-43`)) in -let () = p (BigInt.of-string `2` |> BigInt.pow (BigInt.of-string `3`)) in -let () = p (BigInt.of-string `2` |> BigInt.pow (BigInt.of-string `0`)) in - - -let () = p (BigInt.of-int 12345) in -let () = p (BigInt.of-int (-12345)) in -let () = Debug.log (Int.to-string(BigInt.to-int (BigInt.of-int 12345))) in -let () = Debug.log (Int.to-string(BigInt.to-int (BigInt.of-int (-12345)))) in - - -finish diff --git a/test/big-int.test.satyg b/test/big-int.test.satyg new file mode 100644 index 0000000..140a792 --- /dev/null +++ b/test/big-int.test.satyg @@ -0,0 +1,99 @@ +@require: test/test +@require: test/expect + +@import: ../src/big-int +@import: ../src/eq +@import: ../src/string + +let big-int-test-cases = open Test in + let b = BigInt.of-string in + let beq = Eq.equal BigInt.eq in + let streq = Eq.equal String.eq in + describe `BigInt module` [ + it `parse and print` (fun () -> ( + (b `42` |> BigInt.to-string |> streq `42`) + && (b `-123` |> BigInt.to-string |> streq `-123`) + && (b `-10` |> BigInt.to-string |> streq `-10`) + && (BigInt.zero |> BigInt.to-string |> streq `0`) + && (BigInt.one |> BigInt.to-string |> streq `1`) + && (BigInt.minus-one |> BigInt.to-string |> streq `-1`) + |> Expect.is-true + )); + it `compare via oparators` (fun () -> BigInt.( + b `42` < b `136` + && b `42` <= b `136` + && not (b `42` > b `136`) + && not (b `42` >= b `136`) + && not (b `42` == b `136`) + && not (b `-42` < b `-136`) + |> Expect.is-true + )); + it `compare via ord` (fun () -> ( + let ord = Ord.compare BigInt.ord in + let ordeq = Eq.equal Ordering.eq in + (ord (b `123`) (b `-456`) |> ordeq Gt) + && (ord (b `-123`) (b `456`) |> ordeq Lt) + && (ord (b `333`) (b `333`) |> ordeq Eq) + && (ord (b `-333`) (b `-333`) |> ordeq Eq) + && (ord (b `1234`) (b `432`) |> ordeq Gt) + && (ord (b `432`) (b `1234`) |> ordeq Lt) + && (ord (b `-1234`) (b `-432`) |> ordeq Lt) + && (ord (b `-432`) (b `-1234`) |> ordeq Gt) + && (ord (b `332`) (b `333`) |> ordeq Lt) + && (ord (b `333`) (b `332`) |> ordeq Gt) + && (ord (b `-332`) (b `-333`) |> ordeq Gt) + && (ord (b `-333`) (b `-332`) |> ordeq Lt) + |> Expect.is-true + )); + it `add` (fun () -> ( + (BigInt.add (b `42`) (b `39`) |> beq (b `81`)) + && (BigInt.add (b `42`) (b `-39`) |> beq (b `3`)) + && (BigInt.add (b `-42`) (b `39`) |> beq (b `-3`)) + && (BigInt.add (b `-42`) (b `-39`) |> beq (b `-81`)) + && (BigInt.add (b `42`) (b `45`) |> beq (b `87`)) + && (BigInt.add (b `42`) (b `-45`) |> beq (b `-3`)) + && (BigInt.add (b `-42`) (b `45`) |> beq (b `3`)) + && (BigInt.add (b `-42`) (b `-45`) |> beq (b `-87`)) + |> Expect.is-true + )); + it `sub` (fun () -> ( + (BigInt.sub (b `42`) (b `39`) |> beq (b `3`)) + && (BigInt.sub (b `42`) (b `-39`) |> beq (b `81`)) + && (BigInt.sub (b `-42`) (b `39`) |> beq (b `-81`)) + && (BigInt.sub (b `-42`) (b `-39`) |> beq (b `-3`)) + && (BigInt.sub (b `42`) (b `45`) |> beq (b `-3`)) + && (BigInt.sub (b `42`) (b `-45`) |> beq (b `87`)) + && (BigInt.sub (b `-42`) (b `45`) |> beq (b `-87`)) + && (BigInt.sub (b `-42`) (b `-45`) |> beq (b `3`)) + |> Expect.is-true + )); + it `mul` (fun () -> ( + (BigInt.mul (b `157`) (b `16`) |> beq (b `2512`)) + && (BigInt.mul (b `157`) (b `-16`) |> beq (b `-2512`)) + && (BigInt.mul (b `-157`) (b `16`) |> beq (b `-2512`)) + && (BigInt.mul (b `-157`) (b `-16`) |> beq (b `2512`)) + |> Expect.is-true + )); + it `div, mod, pow` (fun () -> ( + (BigInt.div (b `12345`) (b `43`) |> beq (b `287`)) + && (BigInt.mod- (b `12345`) (b `43`) |> beq (b `4`)) + && (BigInt.div (b `1111111`) (b `4649`) |> beq (b `239`)) + && (BigInt.mod- (b `1111111`) (b `4649`) |> beq (b `0`)) + && (BigInt.div (b `-12345`) (b `43`) |> beq (b `-287`)) % correct? + && (BigInt.mod- (b `-12345`) (b `43`) |> beq (b `4`)) % correct? + && (BigInt.div (b `12345`) (b `-43`) |> beq (b `-287`)) % correct? + && (BigInt.mod- (b `12345`) (b `-43`) |> beq (b `4`)) % correct? + && (BigInt.div (b `-12345`) (b `-43`) |> beq (b `287`)) + && (BigInt.mod- (b `-12345`) (b `-43`) |> beq (b `-4`)) + && (b `2` |> BigInt.pow (b `3`) |> beq (b `8`)) + && (b `2` |> BigInt.pow (b `0`) |> beq (b `1`)) + |> Expect.is-true + )); + it `convert from/to int` (fun () -> ( + ((BigInt.of-int 12345) |> beq (b `12345`)) + && ((BigInt.of-int (-12345)) |> beq (b `-12345`)) + && ((BigInt.of-int 12345) |> BigInt.to-int |> (==) 12345) + && ((BigInt.of-int (-12345)) |> BigInt.to-int |> (==) (-12345)) + |> Expect.is-true + )) + ] diff --git a/test/main.test.saty b/test/main.test.saty index 953fee7..3782d27 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -7,6 +7,7 @@ @import: ../src/string @import: array.test +@import: big-int.test @import: bool.test @import: color.test @import: float.test @@ -27,6 +28,7 @@ open Test in describe `base` [ array-test-cases; + big-int-test-cases; bool-test-cases; color-test-cases; float-test-cases; From ccbdbac0c1697929bb9691dc7a8dedb73081492c Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Tue, 5 Mar 2024 14:22:56 +0900 Subject: [PATCH 32/39] GH-142: Rename test sets --- test/main.test.saty | 4 ++-- test/treemap.test.satyg | 2 +- test/treeset.test.satyg | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/main.test.saty b/test/main.test.saty index 3782d27..329db82 100644 --- a/test/main.test.saty +++ b/test/main.test.saty @@ -43,7 +43,7 @@ describe `base` [ regex-test-cases; stream-test-cases; string-test-cases; - tree-map-test-cases; - tree-set-test-cases; + treemap-test-cases; + treeset-test-cases; ] |> run diff --git a/test/treemap.test.satyg b/test/treemap.test.satyg index 2c24afd..e51a8d2 100644 --- a/test/treemap.test.satyg +++ b/test/treemap.test.satyg @@ -4,7 +4,7 @@ @import: ../src/option-ext @import: ../src/tree-map -let tree-map-test-cases = open Test in +let treemap-test-cases = open Test in let intoeq = Eq.equal (Option.eq Int.eq) in describe `TreeMap module` [ it `get mapping` (fun () -> ( diff --git a/test/treeset.test.satyg b/test/treeset.test.satyg index dc3f86e..6df729d 100644 --- a/test/treeset.test.satyg +++ b/test/treeset.test.satyg @@ -5,7 +5,7 @@ @import: ../src/list-ext @import: ../src/tree-set -let tree-set-test-cases = open Test in +let treeset-test-cases = open Test in let intleq = Eq.equal (List.eq Int.eq) in describe `TreeSet module` [ % REMARK: From c68b5f6aa30427440f799af57b278cc1a8123d83 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Tue, 5 Mar 2024 14:24:44 +0900 Subject: [PATCH 33/39] GH-142: Remove js-based snapshot tests for compiler output --- .../__snapshots__/regression.test.js.snap | 456 ------------------ __test__/regression.test.js | 10 - 2 files changed, 466 deletions(-) delete mode 100644 __test__/__snapshots__/regression.test.js.snap diff --git a/__test__/__snapshots__/regression.test.js.snap b/__test__/__snapshots__/regression.test.js.snap deleted file mode 100644 index d150b77..0000000 --- a/__test__/__snapshots__/regression.test.js.snap +++ /dev/null @@ -1,456 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Check compiler outputs 1`] = ` -"[debug.log] ==== Ref ==== -[debug.log] 1 -[debug.log] 2 -[debug.log] 2:1 -[debug.log] 2 -[debug.log] 1 -[debug.log] ==== String ==== -[debug.log] abc -[debug.log] a;b;c -[debug.log] true -[debug.log] spam -[debug.log] ham -[debug.log] eggs -[debug.log]  -[debug.log] a -[debug.log] b -[debug.log] c -[debug.log] true -[debug.log] true -[debug.log] true -[debug.log] true -[debug.log] true -[debug.log] false -[debug.log] false -[debug.log] abc -[debug.log]  -[debug.log] abc  -[debug.log] abc -[debug.log] GRüßE, JüRGEN -[debug.log] grÜße, jÜrgen -[debug.log] TiTle -[debug.log] tiTle -[debug.log] ==== List ==== -[debug.log]  -[debug.log] 1 -[debug.log] 13245 -[debug.log] 13245 -[debug.log] 245 -[debug.log]  -[debug.log] 132 -[debug.log] 45 -[debug.log] 12345 -[debug.log] 12345 -[debug.log] 12345 -[debug.log] (1,2)(1,1)(2,1) -[debug.log] (1,2)(1,1)(2,1) -[debug.log] (1,2)(1,1)(2,1) -[debug.log] ==== Array ==== -[debug.log] 3 -[debug.log] 43 -[debug.log] 0 -[debug.log] 1 -[debug.log] 2 -[debug.log] 3 -[debug.log] 4 -[debug.log] 5 -[debug.log] 6 -[debug.log] 7 -[debug.log] 8 -[debug.log] 9 -[debug.log] 10 -[debug.log] 9 -[debug.log] 8 -[debug.log] 7 -[debug.log] 6 -[debug.log] 5 -[debug.log] 4 -[debug.log] 3 -[debug.log] 2 -[debug.log] 1 -[debug.log] 10 -[debug.log] 9 -[debug.log] 8 -[debug.log] 7 -[debug.log] 6 -[debug.log] 5 -[debug.log] 4 -[debug.log] 3 -[debug.log] 2 -[debug.log] 1 -[debug.log] 234 -[debug.log] 0 -[debug.log] 0 -[debug.log] 1 -[debug.log] 2 -[debug.log] 3 -[debug.log] 4 -[debug.log] 5 -[debug.log] 6 -[debug.log] 7 -[debug.log] 8 -[debug.log] 9 -[debug.log] ==== RegExp ==== -[debug.log] true -[debug.log] true -[debug.log] Some(0, \\"aabbb\\") -[debug.log] Some(0, \\"aa\\") -[debug.log] None -[debug.log] Some(2, \\"bbb\\") -[debug.log] true -[debug.log] Some(7, \\"le\\") -[debug.log] Some(7, \\"le\\") -[debug.log] Some(10, \\"apple\\") -[debug.log] Some(0, \\" \\") -[debug.log] true -[debug.log] true -[debug.log] true -[debug.log] false -[debug.log] false -[debug.log] true -[debug.log] true -testing long input -false -[debug.log] ==== Parser ==== -[debug.log] aaa -[debug.log] 3 -[debug.log] 10 -[debug.log] bar -[debug.log] ==== Lexer ==== -[debug.log] (| kind = identifier, data = \\"abc\\" |) -[debug.log] (| kind = whitespace, data = \\" \\" |) -[debug.log] (| kind = identifier, data = \\"defg\\" |) -[debug.log] (| kind = whitespace, data = \\" \\" |) -[debug.log] (| kind = identifier, data = \\"hijklMNL\\" |) -[debug.log] (| kind = whitespace, data = \\" \\" |) -[debug.log] (| kind = identifier, data = \\"op123\\" |) -[debug.log] ==== Int ==== -[debug.log] 52 -[debug.log] 13 -[debug.log] 6 -[debug.log] 3 -[debug.log] 1 -[debug.log] 0 -[debug.log] 0 -[debug.log] -13 -[debug.log] -7 -[debug.log] -4 -[debug.log] -2 -[debug.log] -1 -[debug.log] -1 -[debug.log] 8 -[debug.log] 19 -[debug.log] 15 -[debug.log] 7 -[debug.log] 3 -[debug.log] 2305843009213693948 -[debug.log] 12345678 -[debug.log] -123 -[debug.log] 65535 -[debug.log] 8 -[debug.log] 1 -[debug.log] 3 -[debug.log] -4611686018427387904 -[debug.log] Some(123) -[debug.log] Some(-123) -[debug.log] None -[debug.log] Some(10) -[debug.log] ==== Map ==== -[debug.log] a -[debug.log] b -[debug.log] c -[debug.log] a -[debug.log] d -[debug.log] c -[debug.log] ==== Promise ==== -[debug.log] bar -[debug.log] foo -[debug.log] barbaz -[debug.log] foobar -[debug.log] ==== Float ==== -[debug.log] 3.14159265359 -[debug.log] 2.71828182846 -[debug.log] inf == inf = true -[debug.log] inf == -inf = false -[debug.log] inf == -nan = false -[debug.log] inf == 0. = false -[debug.log] inf == -0. = false -[debug.log] inf == 1. = false -[debug.log] -inf == inf = false -[debug.log] -inf == -inf = true -[debug.log] -inf == -nan = false -[debug.log] -inf == 0. = false -[debug.log] -inf == -0. = false -[debug.log] -inf == 1. = false -[debug.log] -nan == inf = false -[debug.log] -nan == -inf = false -[debug.log] -nan == -nan = false -[debug.log] -nan == 0. = false -[debug.log] -nan == -0. = false -[debug.log] -nan == 1. = false -[debug.log] 0. == inf = false -[debug.log] 0. == -inf = false -[debug.log] 0. == -nan = false -[debug.log] 0. == 0. = true -[debug.log] 0. == -0. = true -[debug.log] 0. == 1. = false -[debug.log] -0. == inf = false -[debug.log] -0. == -inf = false -[debug.log] -0. == -nan = false -[debug.log] -0. == 0. = true -[debug.log] -0. == -0. = true -[debug.log] -0. == 1. = false -[debug.log] 1. == inf = false -[debug.log] 1. == -inf = false -[debug.log] 1. == -nan = false -[debug.log] 1. == 0. = false -[debug.log] 1. == -0. = false -[debug.log] 1. == 1. = true -[debug.log] inf -[debug.log] -inf -[debug.log] -nan -[debug.log] 23.1406926328 -[debug.log] 1.14472988585 -[debug.log] 36.4621596072 -[debug.log] 2.51097226443e+17 -[debug.log] 1.41421356237 -[debug.log] 0.497149872694 -[debug.log] 2.22507385851e-308 -[debug.log] 1.11253692925e-308 -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] true -[debug.log] true -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] true -[debug.log] true -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] true -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] true -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] true -[debug.log] false -[debug.log] true -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] 2. -[debug.log] 4. -[debug.log] 6. -[debug.log] -2. -[debug.log] -4. -[debug.log] -6. -[debug.log] 6. -[debug.log] 2. -[debug.log] 3. -[debug.log] 5. -[debug.log] -3. -[debug.log] -4. -[debug.log] -6. -[debug.log] 6. -[debug.log] 3. -[debug.log] 4. -[debug.log] 6. -[debug.log] -2. -[debug.log] -3. -[debug.log] -5. -[debug.log] 6. -[debug.log] 2. -[debug.log] 3. -[debug.log] 5. -[debug.log] -2. -[debug.log] -3. -[debug.log] -5. -[debug.log] 6. -[debug.log] 9.88131291682e-324 -[debug.log] 4.94065645841e-324 -[debug.log] 0. -[debug.log] 4.49423283716e+307 -[debug.log] 8.98846567431e+307 -[debug.log] inf -[debug.log] Some(123.45) -[debug.log] Some(-123.45) -[debug.log] Some(123.) -[debug.log] Some(0.111) -[debug.log] None -[debug.log] ==== Bool ==== -[debug.log] true -[debug.log] false -[debug.log] Some(false) -[debug.log] Some(true) -[debug.log] None -[debug.log] Some(false) -[debug.log] Some(true) -[debug.log] None -[debug.log] ==== Stream ==== -[debug.log] 1 -[debug.log] 1 -[debug.log] 2 -[debug.log] 3 -[debug.log] 5 -[debug.log] 8 -[debug.log] 13 -[debug.log] 21 -[debug.log] 34 -[debug.log] 55 -[debug.log] 89 -[debug.log] 144 -[debug.log] 233 -[debug.log] 377 -[debug.log] 610 -[debug.log] 987 -[debug.log] 1597 -[debug.log] 2584 -[debug.log] 4181 -[debug.log] 6765 -[debug.log] 10946 -[debug.log] 17711 -[debug.log] 28657 -[debug.log] 46368 -[debug.log] 75025 -[debug.log] 121393 -[debug.log] 196418 -[debug.log] 317811 -[debug.log] 514229 -[debug.log] 832040 -[debug.log] 0 -[debug.log] 1 -[debug.log] 2 -[debug.log] 3 -[debug.log] 4 -[debug.log] ==== Fn ==== -[debug.log] 0 -[debug.log] 1 -[debug.log] 2 -[debug.log] 3 -[debug.log] 4 -[debug.log] 5 -[debug.log] 6 -[debug.log] 7 -[debug.log] 8 -[debug.log] 9 -[debug.log] done -[debug.log] ==== TreeSet ==== -[debug.log]  -[debug.log] 2,1,3 -[debug.log] check rotations: -[debug.log] 2,1,3 -[debug.log] 2,1,3 -[debug.log] 2,1,3 -[debug.log] 2,1,3 -[debug.log] 16,8,24,4,12,20,28 -[debug.log] 3,1,16,0,2,8,24,-1,4,12,20,28 -[debug.log] 29,16,31,8,24,30,32,4,12,20,28,33 -[debug.log] 12,9,16,8,10,15,24,4,11,20,28 -[debug.log] 20,16,23,8,17,22,24,4,12,19,28 -[debug.log] check size after insertion: -[debug.log] 0 -[debug.log] 7 -[debug.log] 7 -[debug.log] 7 -[debug.log] 7 -[debug.log] check remove: -[debug.log] 20,8,24,4,12,28 -[debug.log] 20,8,24,4,12 -[debug.log] 8,4,20,12 -[debug.log] 4 -[debug.log] 8,4,20,12 -[debug.log] 4 -[debug.log] 4,2,9,1,3,6,11,0,5,8,10,12,7 -[debug.log] check get: -[debug.log] 20 -[debug.log] -1 -[debug.log] ==== TreeMap ==== -[debug.log] 3 -[debug.log] 2 -[debug.log] 3 -[debug.log] 4 -[debug.log] ==== BigInt ==== -[debug.log] 42 -[debug.log] -123 -[debug.log] -10 -[debug.log] 0 -[debug.log] 1 -[debug.log] -1 -[debug.log] true -[debug.log] true -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] false -[debug.log] Gt -[debug.log] Lt -[debug.log] Eq -[debug.log] Eq -[debug.log] Gt -[debug.log] Lt -[debug.log] Lt -[debug.log] Gt -[debug.log] Lt -[debug.log] Gt -[debug.log] Gt -[debug.log] Lt -[debug.log] 81 -[debug.log] 3 -[debug.log] -3 -[debug.log] -81 -[debug.log] 87 -[debug.log] -3 -[debug.log] 3 -[debug.log] -87 -[debug.log] 3 -[debug.log] 81 -[debug.log] -81 -[debug.log] -3 -[debug.log] -3 -[debug.log] 87 -[debug.log] -87 -[debug.log] 3 -[debug.log] 2512 -[debug.log] -2512 -[debug.log] -2512 -[debug.log] 2512 -[debug.log] 287 -[debug.log] 4 -[debug.log] 239 -[debug.log] 0 -[debug.log] -287 -[debug.log] 4 -[debug.log] -287 -[debug.log] 4 -[debug.log] 287 -[debug.log] -4 -[debug.log] 8 -[debug.log] 1 -[debug.log] 12345 -[debug.log] -12345 -[debug.log] 12345 -[debug.log] -12345 -" -`; diff --git a/__test__/regression.test.js b/__test__/regression.test.js index c589cca..15c9b9b 100644 --- a/__test__/regression.test.js +++ b/__test__/regression.test.js @@ -32,16 +32,6 @@ test("Confirm that satysfi is installed", () => { expect(shell.exec("satysfi -v").code).toBe(0); }); -test("Check compiler outputs", () => { - const compilerOutput = shell - .exec("satysfi satysrc/generic.saty", { silent: true }) - .exec( - "awk '/evaluating texts .../{flag=1;next}/evaluation done/{flag=0}flag'", - { silent: true } - ).stdout; - expect(compilerOutput).toMatchSnapshot(); -}); - test("SATySFi-iT", () => { const result = compileSatysfi("satysrc/satysfi-it.saty"); From cef6fb655c41862c2d103ef3fc26b8bd71495857 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Tue, 5 Mar 2024 15:12:09 +0900 Subject: [PATCH 34/39] GH-142: WIP: Fix ci --- .github/workflows/ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a58248..eb09b1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,11 @@ jobs: unit-test: name: unit tests runs-on: ubuntu-latest + strategy: + matrix: + version: [ 0.0.11 ] container: - image: amutake/satysfi:opam-slim + image: amutake/satysfi:${{ matrix.version }} steps: - uses: actions/checkout@v1 - name: Install Satyrographos dependencies @@ -15,7 +18,7 @@ jobs: export HOME=/root eval $(opam env) opam update - opam pin add --verbose --yes "." + opam pin add satysfi-base.opam "file://${PWD}" satyrographos install -l base - name: Run tests run: | From ab861346297c3ff1dc5a37f3060136566964b75c Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Tue, 5 Mar 2024 15:45:33 +0900 Subject: [PATCH 35/39] GH-142: Run unit tests for satysfi >= 0.0.5 --- .github/workflows/ci.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb09b1c..8acaf56 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,15 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - version: [ 0.0.11 ] + version: [ + 0.0.5, + 0.0.6, + 0.0.7, + 0.0.8, + 0.0.9-6-ge0304803, + 0.0.10, + 0.0.11 + ] container: image: amutake/satysfi:${{ matrix.version }} steps: From 0f1106b7fb0e20176c9cc9c5e28ca1c7a369cbbe Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Tue, 5 Mar 2024 15:58:00 +0900 Subject: [PATCH 36/39] GH-142: Upload report only on failure --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8acaf56..0386572 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,10 +36,11 @@ jobs: - if: always() name: Install Apt dependencies run: apt-get update && apt-get install -y xz-utils liblzma-dev - - name: Upload artifact + - if: ${{ failure() }} + name: Upload artifact uses: actions/upload-artifact@master with: - name: satysfi-test-report + name: satysfi-test-report-${{ matrix.version }} path: test/report.txt regression-test: name: Regression tests From e1a819060691e2d3b4897ab10a28828a5844f789 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Tue, 5 Mar 2024 16:04:29 +0900 Subject: [PATCH 37/39] GH-142: Fix config for regression tests in CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0386572..9d9c1bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,7 @@ jobs: eval $(opam env) opam update opam pin add satysfi ${{ matrix.satysfi-version }} - opam pin add --verbose --yes "." + opam pin add satysfi-base.opam "file://${PWD}" satyrographos install -l base - name: Run regression tests run: | From a526552fa4322048b68b06e4c3efd088360b80ec Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Tue, 5 Mar 2024 16:11:56 +0900 Subject: [PATCH 38/39] GH-142: Pin satysfi version in CI --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d9c1bd..3314366 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,7 @@ jobs: export HOME=/root eval $(opam env) opam update + opam pin add satysfi ${{ matrix.version }} opam pin add satysfi-base.opam "file://${PWD}" satyrographos install -l base - name: Run tests From 236aab290cda85ef67d29622da70db6d52966488 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Tue, 5 Mar 2024 16:23:01 +0900 Subject: [PATCH 39/39] GH-142: Drop support of satysfi:0.0.5 --- .github/workflows/ci.yml | 2 -- satysfi-base.opam | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3314366..225ea29 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,6 @@ jobs: strategy: matrix: version: [ - 0.0.5, 0.0.6, 0.0.7, 0.0.8, @@ -52,7 +51,6 @@ jobs: matrix: satysfi-version: [ - 0.0.5, 0.0.6, 0.0.7, ] diff --git a/satysfi-base.opam b/satysfi-base.opam index c47eb2d..d836992 100644 --- a/satysfi-base.opam +++ b/satysfi-base.opam @@ -18,7 +18,7 @@ homepage: "https://github.com/nyuichi/satysfi-base" bug-reports: "https://github.com/nyuichi/satysfi-base/issues" dev-repo: "git+https://github.com/nyuichi/satysfi-base.git" depends: [ - "satysfi" {>= "0.0.5" & < "0.1"} + "satysfi" {>= "0.0.6" & < "0.1"} "satysfi-dist" "satyrographos" {>= "0.0.2.6" & < "0.0.3"} "satysfi-fonts-dejavu" {>= "2.37"}