Skip to content

Commit

Permalink
Add initial test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
RauliL committed Aug 16, 2017
1 parent 54e2c6b commit 0d23fbd
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{cpp,hpp}]
[*.{cpp,hpp,plorth}]
indent_style = space
indent_size = 2

Expand Down
22 changes: 22 additions & 0 deletions tests/framework.plorth
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
: expect-quote-to-return-true
call >boolean not
( "Assertion failed." value-error throw )
if
;

: test-case
(
array?
( ( expect-quote-to-return-true ) swap for-each )
( expect-quote-to-return-true )
if-else
)
(
swap
>string "✘ " swap + println
throw
)
try
>string "✔ " swap + println
clear
;
145 changes: 145 additions & 0 deletions tests/test-array.plorth
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
"./framework.plorth" import

"length"
[
( [] length nip 0 = ),
( [1, 2, 3] length nip 3 = ),
]
test-case

"includes?"
[
( 2 [1, 2, 3] includes? nip ),
( 4 [1, 2, 3] includes? not nip ),
]
test-case

"index-of"
[
( 2 [1, 2, 3] index-of nip 1 = ),
( 4 [1, 2, 3] index-of nip null = ),
]
test-case

"find"
[
( ( 2 > ) [1, 2, 3] find nip 3 = ),
( ( 3 > ) [1, 2, 3] find nip null = ),
]
test-case

"find-index"
[
( ( 2 > ) [1, 2, 3] find-index nip 2 = ),
( ( 3 > ) [1, 2, 3] find-index nip null = ),
]
test-case

"every?"
[
( ( number? nip ) [1, 2, 3] every? nip ),
( ( number? nip ) [1, "foo", 3] every? nip not ),
]
test-case

"some?"
[
( ( number? nip ) ["foo", "bar", 1] some? nip ),
( ( number? nip ) ["foo", "bar"] some? nip not ),
]
test-case

"reverse"
[
( [1, 2, 3] reverse [3, 2, 1] = ),
]
test-case

"uniq"
[
( [1, 1, 2, 2, 3, 3] uniq [1, 2, 3] = ),
]
test-case

"extract"
[
( ["test"] extract "test" = ),
]
test-case

"join"
[
( ", " ["foo", "bar"] join "foo, bar" = ),
]
test-case

"for-each"
[
( (drop true) [1] for-each ),
]
test-case

"map"
[
( ( 1 + ) [1, 2, 3] map [2, 3, 4] = ),
]
test-case

"filter"
[
( ( 1 > ) [1, 2, 3] filter [2, 3] = ),
( ( 3 > ) [1, 2, 3] filter [] = ),
]
test-case

"reduce"
[
( ( + ) [1, 2, 3] reduce 6 = ),
]
test-case

"+"
[
( [1] [2] + [1, 2] = ),
( [] [] + length nip 0 = ),
( [1] [] + length nip 1 = ),
]
test-case

"*"
[
( 2 [1, 2] * [1, 2, 1, 2] = ),
( 1 [] * length nip 0 = ),
( 0 [1, 2, 3] * length nip 0 = ),
]
test-case

"&"
[
( [1, 1, 2, 3, 4] [1, 4, 4] & [1, 4] = ),
]
test-case

"|"
[
( [1, 1, 2, 2] [2, 2, 3, 3, 4] | [1, 2, 3, 4] = ),
]
test-case

"@"
[
( 0 [1, 2, 3] @ nip 1 = ),
( -1 [1, 2, 3] @ nip 3 = ),
( -2 [1, 2, 3] @ nip 2 = ),
( 2 [1, 2, 3] @ nip 3 = ),
]
test-case

"!"
[
( "foo" 0 [1, 2, 3] ! ["foo", 2, 3] = ),
( "foo" -1 [1, 2, 3] ! [1, 2, "foo"] = ),
( "foo" -2 [1, 2, 3] ! [1, "foo", 3] = ),
( "foo" 2 [1, 2, 3] ! [1, 2, "foo"] = ),
]
test-case
13 changes: 13 additions & 0 deletions tests/test-boolean.plorth
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"./framework.plorth" import

"and"
( true true and ) expect

"or"
( false true or ) expect

"xor"
( true false xor ) expect

"not"
( true not false = ) expect

0 comments on commit 0d23fbd

Please sign in to comment.