diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-03 13:19:41 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-03 13:19:41 -0400 |
| commit | 64143f0a131a053414e4b73c17bff994522b11c2 (patch) | |
| tree | 2545507fde623f8846bf183388acdbb0234b5e65 /test | |
| parent | 5feecff9d93522002c74a1423d138c2aa8bc150d (diff) | |
Syntax overhaul (comments back to `#`, print statments to `!!`),
using `$/.../` for patterns and using a DSL for patterns
Diffstat (limited to 'test')
| -rw-r--r-- | test/arrays.tm | 10 | ||||
| -rw-r--r-- | test/integers.tm | 2 | ||||
| -rw-r--r-- | test/lambdas.tm | 4 | ||||
| -rw-r--r-- | test/lang.tm | 10 | ||||
| -rw-r--r-- | test/text.tm | 85 | ||||
| -rw-r--r-- | test/threads.tm | 8 |
6 files changed, 62 insertions, 57 deletions
diff --git a/test/arrays.tm b/test/arrays.tm index 21c8cb5c..16f411a2 100644 --- a/test/arrays.tm +++ b/test/arrays.tm @@ -78,23 +78,23 @@ func main(): >> arr := [10, 20, 30] >> reversed := arr:reversed() = [30, 20, 10] - // Ensure the copy-on-write behavior triggers: + # Ensure the copy-on-write behavior triggers: >> arr[1] = 999 >> reversed = [30, 20, 10] do: >> nums := [10, -20, 30] - // Sorted function doesn't mutate original: + # Sorted function doesn't mutate original: >> nums:sorted() = [-20, 10, 30] >> nums = [10, -20, 30] - // Sort function does mutate in place: + # Sort function does mutate in place: >> nums:sort() >> nums = [-20, 10, 30] - // Custom sort functions: + # Custom sort functions: >> nums:sort(func(x:&%Int,y:&%Int): x:abs() <> y:abs()) >> nums = [10, -20, 30] @@ -148,7 +148,7 @@ func main(): >> [i*10 for i in 10]:by(2):by(-1) = [90, 70, 50, 30, 10] - // Test iterating over array:from() and array:to() + # Test iterating over array:from() and array:to() xs := ["A", "B", "C", "D"] for i,x in xs:to(-2): for y in xs:from(i+1): diff --git a/test/integers.tm b/test/integers.tm index 5743cbb2..e15b9473 100644 --- a/test/integers.tm +++ b/test/integers.tm @@ -79,7 +79,7 @@ func main(): for in 20: >> n := Int.random(-999999, 999999) >> d := Int.random(-999, 999) - //! n=$n, d=$d: + !! n=$n, d=$d: >> (n/d)*d + (n mod d) == n = yes diff --git a/test/lambdas.tm b/test/lambdas.tm index 8d543bfc..62b5fd36 100644 --- a/test/lambdas.tm +++ b/test/lambdas.tm @@ -31,12 +31,12 @@ func main(): >> abs100(-5) = 500 - // Test nested lambdas: + # Test nested lambdas: outer := "Hello" fn := func(): return func(): return func(): - defer: //! $outer + defer: !! $outer return outer >> fn()()() = "Hello" diff --git a/test/lang.tm b/test/lang.tm index d78476de..e2093a6e 100644 --- a/test/lang.tm +++ b/test/lang.tm @@ -1,11 +1,11 @@ lang HTML: HEADER := $HTML"<!DOCTYPE HTML>" func escape(t:Text)->HTML: - t = t:replace("&", "&") - t = t:replace("<", "<") - t = t:replace(">", ">") - t = t:replace('"', """) - t = t:replace("'", "'") + t = t:replace($/&/, "&") + t = t:replace($/</, "<") + t = t:replace($/>/, ">") + t = t:replace($/"/, """) + t = t:replace($/'/, "'") return HTML.from_unsafe_text(t) func escape_int(i:Int)->HTML: diff --git a/test/text.tm b/test/text.tm index d82a38c7..3049af99 100644 --- a/test/text.tm +++ b/test/text.tm @@ -1,6 +1,6 @@ func main(): >> str := "Hello Amélie!" - //! Testing strings like $str + !! Testing strings like $str >> str:upper() = "HELLO AMÉLIE!" @@ -40,45 +40,45 @@ func main(): >> amelie2:codepoint_names() = ["LATIN CAPITAL LETTER A", "LATIN SMALL LETTER M", "LATIN SMALL LETTER E WITH ACUTE", "LATIN SMALL LETTER L", "LATIN SMALL LETTER I", "LATIN SMALL LETTER E"] - >> "Hello":replace("e", "X") + >> "Hello":replace($/e/, "X") = "HXllo" - >> "Hello":has("l") + >> "Hello":has($/l/) = yes - >> "Hello":has("l[..end]") + >> "Hello":has($/l[..end]/) = no - >> "Hello":has("[..start]l") + >> "Hello":has($/[..start]l/) = no - >> "Hello":has("o") + >> "Hello":has($/o/) = yes - >> "Hello":has("o[..end]") + >> "Hello":has($/o[..end]/) = yes - >> "Hello":has("[..start]o") + >> "Hello":has($/[..start]o/) = no - >> "Hello":has("H") + >> "Hello":has($/H/) = yes - >> "Hello":has("H[..end]") + >> "Hello":has($/H[..end]/) = no - >> "Hello":has("[..start]H") + >> "Hello":has($/[..start]H/) = yes - >> "Hello":replace("l", "") + >> "Hello":replace($/l/, "") = "Heo" - >> "xxxx":replace("x", "") + >> "xxxx":replace($/x/, "") = "" - >> "xxxx":replace("y", "") + >> "xxxx":replace($/y/, "") = "xxxx" - >> "One two three four five six":replace("e ", "") + >> "One two three four five six":replace($/e /, "") = "Ontwo threfour fivsix" - >> " one ":replace("[..start][..space]", "") + >> " one ":replace($/[..start][..space]/, "") = "one " - >> " one ":replace("[..space][..end]", "") + >> " one ":replace($/[..space][..end]/, "") = " one" - >> amelie:has(amelie2) + >> amelie:has($/$amelie2/) >> multiline := " @@ -87,7 +87,7 @@ func main(): " = "line one\nline two" - //! Interpolation tests: + !! Interpolation tests: >> "A $(1+2)" = "A 3" >> 'A $(1+2)' @@ -104,9 +104,9 @@ func main(): >> $(one (nested) two $(1+2)) = "one (nested) two 3" - >> "one two three":replace("[..alpha]", "") + >> "one two three":replace($/[..alpha]/, "") = " " - >> "one two three":replace("[..alpha]", "word") + >> "one two three":replace($/[..alpha]/, "word") = "word word word" >> c := "É̩" @@ -130,17 +130,17 @@ func main(): >> "":lines() = [] - //! Test splitting and joining text: - >> "one two three":split(" ") + !! Test splitting and joining text: + >> "one two three":split($/ /) = ["one", "two", "three"] - >> "one,two,three,":split(",") + >> "one,two,three,":split($/,/) = ["one", "two", "three", ""] - >> "one two three":split("[..space]") + >> "one two three":split($/[..space]/) = ["one", "two", "three"] - >> "abc":split("") + >> "abc":split($//) = ["a", "b", "c"] >> ", ":join(["one", "two", "three"]) @@ -158,42 +158,42 @@ func main(): >> "":split() = [] - //! Test text:find_all() - >> " one two three ":find_all("[..alpha]") + !! Test text:find_all() + >> " one two three ":find_all($/[..alpha]/) = ["one", "two", "three"] - >> " one two three ":find_all("[..!space]") + >> " one two three ":find_all($/[..!space]/) = ["one", "two", "three"] - >> " ":find_all("[..alpha]") + >> " ":find_all($/[..alpha]/) = [] - >> " foo(baz(), 1) doop() ":find_all("[..id](?)") + >> " foo(baz(), 1) doop() ":find_all($/[..id](?)/) = ["foo(baz(), 1)", "doop()"] - >> "":find_all("") + >> "":find_all($Pattern'') = [] - >> "Hello":find_all("") + >> "Hello":find_all($Pattern'') = [] - //! Test text:find() - >> " one two three ":find("[..id]", start=-999) + !! Test text:find() + >> " one two three ":find($/[..id]/, start=-999) = 0 - >> " one two three ":find("[..id]", start=999) + >> " one two three ":find($/[..id]/, start=999) = 0 - >> " one two three ":find("[..id]") + >> " one two three ":find($/[..id]/) = 2 - >> " one two three ":find("[..id]", start=5) + >> " one two three ":find($/[..id]/, start=5) = 8 >> len := 0_i64 - >> " one ":find("[..id]", length=&len) + >> " one ":find($/[..id]/, length=&len) = 4 >> len = 3_i64 - //! Test text slicing: + !! Test text slicing: >> "abcdef":slice() = "abcdef" >> "abcdef":slice(from=3) @@ -220,3 +220,8 @@ func main(): >> Text.from_codepoint_names(["not a valid name here buddy"]) = "" + >> malicious := "[..xxx" + >> $/$malicious/ + = $/[..1[]..xxx/ + + diff --git a/test/threads.tm b/test/threads.tm index 986ab864..2f259a0e 100644 --- a/test/threads.tm +++ b/test/threads.tm @@ -26,7 +26,7 @@ func main(): results := |:Int; max_size| >> thread := Thread.new(func(): - //! In another thread! + !! In another thread! while yes: >> got := jobs:get() when got is Increment(x): @@ -63,8 +63,8 @@ func main(): >> results:get() = 1001 - //! Canceling... + !! Canceling... >> thread:cancel() - //! Joining... + !! Joining... >> thread:join() - //! Done! + !! Done! |
