factor/core/parser/parser-tests.factor

463 lines
12 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
USING: arrays math parser tools.test kernel generic words
io.streams.string namespaces classes effects source-files
assocs sequences strings io.files definitions continuations
sorting classes.tuple compiler.units debugger vocabs
2008-04-04 04:46:30 -04:00
vocabs.loader accessors ;
2008-04-25 02:54:42 -04:00
2008-03-01 17:00:45 -05:00
IN: parser.tests
2007-09-20 18:09:08 -04:00
[
[ 1 [ 2 [ 3 ] 4 ] 5 ]
[ "1\n[\n2\n[\n3\n]\n4\n]\n5" eval ]
2007-09-20 18:09:08 -04:00
unit-test
[ t t f f ]
[ "t t f f" eval ]
2007-09-20 18:09:08 -04:00
unit-test
[ "hello world" ]
[ "\"hello world\"" eval ]
2007-09-20 18:09:08 -04:00
unit-test
[ "\n\r\t\\" ]
[ "\"\\n\\r\\t\\\\\"" eval ]
2007-09-20 18:09:08 -04:00
unit-test
[ "hello world" ]
[
2008-03-01 17:00:45 -05:00
"IN: parser.tests : hello \"hello world\" ;"
2008-03-03 17:44:24 -05:00
eval "USE: parser.tests hello" eval
2007-09-20 18:09:08 -04:00
] unit-test
[ ]
[ "! This is a comment, people." eval ]
2007-09-20 18:09:08 -04:00
unit-test
! Test escapes
[ " " ]
[ "\"\\u000020\"" eval ]
2007-09-20 18:09:08 -04:00
unit-test
[ "'" ]
[ "\"\\u000027\"" eval ]
2007-09-20 18:09:08 -04:00
unit-test
! Test EOL comments in multiline strings.
[ "Hello" ] [ "#! This calls until-eol.\n\"Hello\"" eval ] unit-test
2007-09-20 18:09:08 -04:00
[ word ] [ \ f class ] unit-test
! Test stack effect parsing
: effect-parsing-test ( a b -- c ) + ;
[ t ] [
2008-03-01 17:00:45 -05:00
"effect-parsing-test" "parser.tests" lookup
2007-09-20 18:09:08 -04:00
\ effect-parsing-test eq?
] unit-test
[ T{ effect f { "a" "b" } { "c" } f } ]
[ \ effect-parsing-test "declared-effect" word-prop ] unit-test
: baz ( a b -- * ) 2array throw ;
[ t ]
[ \ baz "declared-effect" word-prop effect-terminated? ]
unit-test
2008-03-01 17:00:45 -05:00
[ ] [ "IN: parser.tests USE: math : effect-parsing-test ( a b -- d ) - ;" eval ] unit-test
2007-09-20 18:09:08 -04:00
[ t ] [
2008-03-01 17:00:45 -05:00
"effect-parsing-test" "parser.tests" lookup
2007-09-20 18:09:08 -04:00
\ effect-parsing-test eq?
] unit-test
[ T{ effect f { "a" "b" } { "d" } f } ]
[ \ effect-parsing-test "declared-effect" word-prop ] unit-test
2008-03-01 17:00:45 -05:00
[ ] [ "IN: parser.tests : effect-parsing-test ;" eval ] unit-test
2007-09-20 18:09:08 -04:00
[ f ] [ \ effect-parsing-test "declared-effect" word-prop ] unit-test
! Funny bug
2008-03-01 17:00:45 -05:00
[ 2 ] [ "IN: parser.tests : \0. 2 ; \0." eval ] unit-test
2007-09-20 18:09:08 -04:00
2008-03-01 17:00:45 -05:00
[ "IN: parser.tests : missing-- ( a b ) ;" eval ] must-fail
2007-09-20 18:09:08 -04:00
! These should throw errors
[ "HEX: zzz" eval ] must-fail
[ "OCT: 999" eval ] must-fail
[ "BIN: --0" eval ] must-fail
2007-09-20 18:09:08 -04:00
! Another funny bug
[ t ] [
[
"scratchpad" in set
{ "scratchpad" "arrays" } set-use
[
! This shouldn't modify in/use in the outer scope!
] with-file-vocabs
2007-09-20 18:09:08 -04:00
use get { "scratchpad" "arrays" } set-use use get =
] with-scope
] unit-test
DEFER: foo
2008-03-01 17:00:45 -05:00
"IN: parser.tests USING: math prettyprint ; : foo 2 2 + . ; parsing" eval
2007-09-20 18:09:08 -04:00
2008-03-03 17:44:24 -05:00
[ ] [ "USE: parser.tests foo" eval ] unit-test
2007-09-20 18:09:08 -04:00
2008-03-01 17:00:45 -05:00
"IN: parser.tests USING: math prettyprint ; : foo 2 2 + . ;" eval
2007-09-20 18:09:08 -04:00
[ t ] [
2008-03-03 17:44:24 -05:00
"USE: parser.tests \\ foo" eval
2008-03-01 17:00:45 -05:00
"foo" "parser.tests" lookup eq?
2007-09-20 18:09:08 -04:00
] unit-test
! Test smudging
[ 1 ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests : smudge-me ;" <string-reader> "foo"
2007-09-20 18:09:08 -04:00
parse-stream drop
2007-12-24 17:18:26 -05:00
"foo" source-file source-file-definitions first assoc-size
2007-09-20 18:09:08 -04:00
] unit-test
2008-03-01 17:00:45 -05:00
[ t ] [ "smudge-me" "parser.tests" lookup >boolean ] unit-test
2007-09-20 18:09:08 -04:00
[ ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests : smudge-me-more ;" <string-reader> "foo"
2007-09-20 18:09:08 -04:00
parse-stream drop
] unit-test
2008-03-01 17:00:45 -05:00
[ t ] [ "smudge-me-more" "parser.tests" lookup >boolean ] unit-test
[ f ] [ "smudge-me" "parser.tests" lookup >boolean ] unit-test
2007-09-20 18:09:08 -04:00
[ 3 ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests USING: math strings ; GENERIC: smudge-me M: integer smudge-me ; M: string smudge-me ;" <string-reader> "foo"
2007-09-20 18:09:08 -04:00
parse-stream drop
2007-12-24 17:18:26 -05:00
"foo" source-file source-file-definitions first assoc-size
2007-09-20 18:09:08 -04:00
] unit-test
[ 1 ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests USING: arrays ; M: array smudge-me ;" <string-reader> "bar"
2007-09-20 18:09:08 -04:00
parse-stream drop
2007-12-24 17:18:26 -05:00
"bar" source-file source-file-definitions first assoc-size
2007-09-20 18:09:08 -04:00
] unit-test
[ 2 ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests USING: math strings ; GENERIC: smudge-me M: integer smudge-me ;" <string-reader> "foo"
2007-09-20 18:09:08 -04:00
parse-stream drop
2007-12-24 17:18:26 -05:00
"foo" source-file source-file-definitions first assoc-size
2007-09-20 18:09:08 -04:00
] unit-test
[ t ] [
2008-03-01 17:00:45 -05:00
array "smudge-me" "parser.tests" lookup order memq?
2007-09-20 18:09:08 -04:00
] unit-test
[ t ] [
2008-03-01 17:00:45 -05:00
integer "smudge-me" "parser.tests" lookup order memq?
2007-09-20 18:09:08 -04:00
] unit-test
[ f ] [
2008-03-01 17:00:45 -05:00
string "smudge-me" "parser.tests" lookup order memq?
2007-09-20 18:09:08 -04:00
] unit-test
[ ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests USE: math 2 2 +" <string-reader> "a"
2007-09-20 18:09:08 -04:00
parse-stream drop
] unit-test
[ t ] [
"a" <pathname> \ + usage member?
] unit-test
[ ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests USE: math 2 2 -" <string-reader> "a"
2007-09-20 18:09:08 -04:00
parse-stream drop
] unit-test
[ f ] [
"a" <pathname> \ + usage member?
] unit-test
[ ] [
"a" source-files get delete-at
2 [
2008-03-01 17:00:45 -05:00
"IN: parser.tests DEFER: x : y x ; : x y ;"
2007-09-20 18:09:08 -04:00
<string-reader> "a" parse-stream drop
] times
] unit-test
"a" source-files get delete-at
[
2008-03-01 17:00:45 -05:00
"IN: parser.tests : x ; : y 3 throw ; this is an error"
<string-reader> "a" parse-stream
] [ parse-error? ] must-fail-with
2007-09-20 18:09:08 -04:00
[ t ] [
2008-03-01 17:00:45 -05:00
"y" "parser.tests" lookup >boolean
2007-09-20 18:09:08 -04:00
] unit-test
[ f ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests : x ;"
2007-09-20 18:09:08 -04:00
<string-reader> "a" parse-stream drop
2008-03-01 17:00:45 -05:00
"y" "parser.tests" lookup
2007-09-20 18:09:08 -04:00
] unit-test
! Test new forward definition logic
[ ] [
"IN: axx : axx ;"
<string-reader> "axx" parse-stream drop
] unit-test
[ ] [
"USE: axx IN: bxx : bxx ; : cxx axx bxx ;"
<string-reader> "bxx" parse-stream drop
] unit-test
! So we move the bxx word to axx...
[ ] [
"IN: axx : axx ; : bxx ;"
<string-reader> "axx" parse-stream drop
] unit-test
[ t ] [ "bxx" "axx" lookup >boolean ] unit-test
! And reload the file that uses it...
[ ] [
"USE: axx IN: bxx : cxx axx bxx ;"
<string-reader> "bxx" parse-stream drop
] unit-test
! And hope not to get a forward-error!
! Turning a generic into a non-generic could cause all
! kinds of funnyness
[ ] [
"IN: ayy USE: kernel GENERIC: ayy M: object ayy ;"
<string-reader> "ayy" parse-stream drop
] unit-test
[ ] [
"IN: ayy USE: kernel : ayy ;"
<string-reader> "ayy" parse-stream drop
] unit-test
[ ] [
"IN: azz TUPLE: my-class ; GENERIC: a-generic"
<string-reader> "azz" parse-stream drop
] unit-test
[ ] [
"USE: azz M: my-class a-generic ;"
<string-reader> "azz-2" parse-stream drop
] unit-test
[ ] [
"IN: azz GENERIC: a-generic"
<string-reader> "azz" parse-stream drop
] unit-test
[ ] [
"USE: azz USE: math M: integer a-generic ;"
<string-reader> "azz-2" parse-stream drop
] unit-test
[ ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests : <bogus-error> ; : bogus <bogus-error> ;"
2007-09-20 18:09:08 -04:00
<string-reader> "bogus-error" parse-stream drop
] unit-test
[ ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests TUPLE: bogus-error ; C: <bogus-error> bogus-error : bogus <bogus-error> ;"
2007-09-20 18:09:08 -04:00
<string-reader> "bogus-error" parse-stream drop
] unit-test
! Problems with class predicates -vs- ordinary words
[ ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests TUPLE: killer ;"
2007-09-20 18:09:08 -04:00
<string-reader> "removing-the-predicate" parse-stream drop
] unit-test
[ ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests GENERIC: killer? ( a -- b )"
2007-09-20 18:09:08 -04:00
<string-reader> "removing-the-predicate" parse-stream drop
] unit-test
[ t ] [
2008-03-01 17:00:45 -05:00
"killer?" "parser.tests" lookup >boolean
2007-09-20 18:09:08 -04:00
] unit-test
[
2008-03-01 17:00:45 -05:00
"IN: parser.tests TUPLE: another-pred-test ; GENERIC: another-pred-test?"
<string-reader> "removing-the-predicate" parse-stream
2008-04-04 04:46:30 -04:00
] [ error>> error>> redefine-error? ] must-fail-with
[
2008-03-01 17:00:45 -05:00
"IN: parser.tests TUPLE: class-redef-test ; TUPLE: class-redef-test ;"
<string-reader> "redefining-a-class-1" parse-stream
2008-04-04 04:46:30 -04:00
] [ error>> error>> redefine-error? ] must-fail-with
[ ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests TUPLE: class-redef-test ; SYMBOL: class-redef-test"
<string-reader> "redefining-a-class-2" parse-stream drop
] unit-test
[
2008-03-01 17:00:45 -05:00
"IN: parser.tests TUPLE: class-redef-test ; SYMBOL: class-redef-test : class-redef-test ;"
<string-reader> "redefining-a-class-3" parse-stream drop
2008-04-04 04:46:30 -04:00
] [ error>> error>> redefine-error? ] must-fail-with
2007-12-22 15:47:10 -05:00
[ ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests TUPLE: class-fwd-test ;"
2007-12-22 15:47:10 -05:00
<string-reader> "redefining-a-class-3" parse-stream drop
] unit-test
[
2008-03-01 17:00:45 -05:00
"IN: parser.tests \\ class-fwd-test"
<string-reader> "redefining-a-class-3" parse-stream drop
2008-04-04 04:46:30 -04:00
] [ error>> error>> no-word-error? ] must-fail-with
2007-12-22 15:47:10 -05:00
[ ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests TUPLE: class-fwd-test ; SYMBOL: class-fwd-test"
2007-12-22 15:47:10 -05:00
<string-reader> "redefining-a-class-3" parse-stream drop
] unit-test
[
2008-03-01 17:00:45 -05:00
"IN: parser.tests \\ class-fwd-test"
<string-reader> "redefining-a-class-3" parse-stream drop
2008-04-04 04:46:30 -04:00
] [ error>> error>> no-word-error? ] must-fail-with
2007-12-25 18:10:05 -05:00
[
2008-03-01 17:00:45 -05:00
"IN: parser.tests : foo ; TUPLE: foo ;"
<string-reader> "redefining-a-class-4" parse-stream drop
2008-04-04 04:46:30 -04:00
] [ error>> error>> redefine-error? ] must-fail-with
2008-02-06 20:23:39 -05:00
[ ] [
2008-03-01 17:00:45 -05:00
"IN: parser.tests : foo ( x y -- z ) 1 2 ; : bar ( a -- b ) ;" eval
2008-02-06 20:23:39 -05:00
] unit-test
[
2008-03-01 17:00:45 -05:00
"IN: parser.tests : foo ( x y -- z) 1 2 ; : bar ( a -- b ) ;" eval
2008-02-06 20:23:39 -05:00
] must-fail
] with-file-vocabs
2007-09-20 18:09:08 -04:00
2007-12-24 19:40:09 -05:00
[ ] [
2008-03-26 19:23:19 -04:00
"IN: parser.tests USE: kernel PREDICATE: foo < object ( x -- y ) ;" eval
2007-12-24 19:40:09 -05:00
] unit-test
[ t ] [
2008-03-01 17:00:45 -05:00
"foo?" "parser.tests" lookup word eq?
2007-12-24 19:40:09 -05:00
] unit-test
2008-02-24 01:26:54 -05:00
[ ] [
2008-03-18 22:43:29 -04:00
[
"redefining-a-class-5" forget-source
"redefining-a-class-6" forget-source
"redefining-a-class-7" forget-source
] with-compilation-unit
2008-02-24 01:26:54 -05:00
] unit-test
2008-03-18 22:43:29 -04:00
2 [
[ ] [
"IN: parser.tests TUPLE: foo ; GENERIC: foo"
<string-reader> "redefining-a-class-5" parse-stream drop
] unit-test
2008-02-24 01:26:54 -05:00
2008-03-18 22:43:29 -04:00
[ ] [
"IN: parser.tests M: f foo ;"
<string-reader> "redefining-a-class-6" parse-stream drop
] unit-test
2008-02-24 01:26:54 -05:00
2008-03-18 22:43:29 -04:00
[ f ] [ f "foo" "parser.tests" lookup execute ] unit-test
[ ] [
"IN: parser.tests TUPLE: foo ; GENERIC: foo"
<string-reader> "redefining-a-class-5" parse-stream drop
] unit-test
2008-02-24 01:26:54 -05:00
2008-03-18 22:43:29 -04:00
[ f ] [ f "foo" "parser.tests" lookup execute ] unit-test
2008-02-24 01:26:54 -05:00
2008-03-18 22:43:29 -04:00
[ ] [
"IN: parser.tests TUPLE: foo ; GENERIC: foo"
2008-02-24 01:26:54 -05:00
<string-reader> "redefining-a-class-7" parse-stream drop
2008-03-18 22:43:29 -04:00
] unit-test
2008-02-24 01:26:54 -05:00
2008-03-18 22:43:29 -04:00
[ f ] [ f "foo" "parser.tests" lookup execute ] unit-test
[ ] [
"IN: parser.tests TUPLE: foo ;"
<string-reader> "redefining-a-class-7" parse-stream drop
] unit-test
2008-02-24 01:26:54 -05:00
2008-03-18 22:43:29 -04:00
[ t ] [ "foo" "parser.tests" lookup symbol? ] unit-test
] times
2008-02-26 22:03:14 -05:00
[ "resource:core/parser/test/assert-depth.factor" run-file ]
[ relative-overflow-stack { 1 2 3 } sequence= ]
must-fail-with
2008-03-13 07:38:09 -04:00
2 [
[ ] [
"IN: parser.tests DEFER: d-f-s d-f-s SYMBOL: d-f-s d-f-s"
<string-reader> "d-f-s-test" parse-stream drop
] unit-test
[ ] [
"IN: parser.tests DEFER: d-f-s d-f-s FORGET: d-f-s SYMBOL: d-f-s d-f-s"
<string-reader> "d-f-s-test" parse-stream drop
] unit-test
[ ] [
"IN: parser.tests DEFER: d-f-s d-f-s SYMBOL: d-f-s d-f-s"
<string-reader> "d-f-s-test" parse-stream drop
] unit-test
] times
2008-03-18 18:46:25 -04:00
[ ] [ "parser" reload ] unit-test
2008-03-20 18:58:35 -04:00
[ ] [
[ "this-better-not-exist" forget-vocab ] with-compilation-unit
] unit-test
[
"USE: this-better-not-exist" eval
] must-fail
2008-04-25 02:54:42 -04:00
[ ": foo ;" eval ] [ error>> no-current-vocab? ] must-fail-with
[ 92 ] [ "CHAR: \\" eval ] unit-test
[ 92 ] [ "CHAR: \\\\" eval ] unit-test
[ ] [
{
"IN: parser.tests"
"USING: math arrays ;"
"GENERIC: change-combination"
"M: integer change-combination 1 ;"
"M: array change-combination 2 ;"
} "\n" join <string-reader> "change-combination-test" parse-stream drop
] unit-test
[ ] [
{
"IN: parser.tests"
"USING: math arrays ;"
"GENERIC# change-combination 1"
"M: integer change-combination 1 ;"
"M: array change-combination 2 ;"
} "\n" join <string-reader> "change-combination-test" parse-stream drop
] unit-test
[ 2 ] [
"change-combination" "parser.tests" lookup
"methods" word-prop assoc-size
] unit-test