factor/core/vocabs/loader/loader-tests.factor

146 lines
3.1 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Unit tests for vocabs.loader vocabulary
IN: temporary
USING: vocabs.loader tools.test continuations vocabs math
kernel arrays sequences namespaces io.streams.string
parser source-files words assocs tuples definitions
2008-01-09 19:13:26 -05:00
debugger compiler.units ;
2007-09-20 18:09:08 -04:00
! This vocab should not exist, but just in case...
[ ] [
[
"vocabs.loader.test" forget-vocab
] with-compilation-unit
] unit-test
2007-09-20 18:09:08 -04:00
[ T{ vocab-link f "vocabs.loader.test" } ]
[ "vocabs.loader.test" f >vocab-link ] unit-test
[ t ]
[ "kernel" f >vocab-link "kernel" vocab = ] unit-test
[ t ] [
"kernel" vocab-files
"kernel" vocab vocab-files
"kernel" f <vocab-link> vocab-files
2007-09-20 18:09:08 -04:00
3array all-equal?
] unit-test
IN: vocabs.loader.test.2
: hello 3 ;
MAIN: hello
IN: temporary
[ { 3 3 3 } ] [
"vocabs.loader.test.2" run
"vocabs.loader.test.2" vocab run
"vocabs.loader.test.2" f <vocab-link> run
2007-09-20 18:09:08 -04:00
3array
] unit-test
2008-01-09 19:13:26 -05:00
[
"resource:core/vocabs/loader/test/a/a.factor" forget-source
"vocabs.loader.test.a" forget-vocab
] with-compilation-unit
2007-09-20 18:09:08 -04:00
0 "count-me" set-global
2 [
[ "vocabs.loader.test.a" require ] must-fail
2007-09-20 18:09:08 -04:00
[ f ] [ "vocabs.loader.test.a" vocab-source-loaded? ] unit-test
[ t ] [
"resource:core/vocabs/loader/test/a/a.factor"
source-file source-file-definitions dup USE: prettyprint .
"v-l-t-a-hello" "vocabs.loader.test.a" lookup dup .
2007-12-24 19:40:09 -05:00
swap first key?
2007-09-20 18:09:08 -04:00
] unit-test
] times
[ 2 ] [ "count-me" get-global ] unit-test
[ t ] [
[
"IN: vocabs.loader.test.a v-l-t-a-hello"
<string-reader>
"resource:core/vocabs/loader/test/a/a.factor"
parse-stream
2008-02-05 00:30:59 -05:00
] catch [ no-word? ] is?
2007-09-20 18:09:08 -04:00
] unit-test
0 "count-me" set-global
[ ] [
[
"vocabs.loader.test.b" forget-vocab
] with-compilation-unit
] unit-test
2007-09-20 18:09:08 -04:00
[ ] [
2008-01-09 19:13:26 -05:00
[
"vocabs.loader.test.b" vocab-files
[ forget-source ] each
] with-compilation-unit
2007-09-20 18:09:08 -04:00
] unit-test
[ "vocabs.loader.test.b" require ] must-fail
2007-09-20 18:09:08 -04:00
[ 1 ] [ "count-me" get-global ] unit-test
[ ] [
2007-12-24 19:40:09 -05:00
[
2008-01-02 19:36:36 -05:00
"bob" "vocabs.loader.test.b" create [ ] define
2007-12-24 19:40:09 -05:00
] with-compilation-unit
2007-09-20 18:09:08 -04:00
] unit-test
[ ] [ "vocabs.loader.test.b" refresh ] unit-test
[ 2 ] [ "count-me" get-global ] unit-test
2008-01-02 19:36:36 -05:00
[ f ] [ "fred" "vocabs.loader.test.b" lookup undefined? ] unit-test
2007-09-20 18:09:08 -04:00
[ ] [
2008-01-09 19:13:26 -05:00
[
"vocabs.loader.test.b" vocab-files
[ forget-source ] each
] with-compilation-unit
2007-09-20 18:09:08 -04:00
] unit-test
[ ] [ "vocabs.loader.test.b" refresh ] unit-test
[ 3 ] [ "count-me" get-global ] unit-test
[ { "resource:core/kernel/kernel.factor" 1 } ]
[ "kernel" f <vocab-link> where ] unit-test
2007-09-20 18:09:08 -04:00
[ { "resource:core/kernel/kernel.factor" 1 } ]
[ "kernel" vocab where ] unit-test
[ t ] [
[ "vocabs.loader.test.d" require ] catch
[ :1 ] when
"vocabs.loader.test.d" vocab-source-loaded?
] unit-test
: forget-junk
[
{ "2" "a" "b" "d" "e" "f" }
[
"vocabs.loader.test." swap append forget-vocab
] each
] with-compilation-unit ;
2007-09-20 18:09:08 -04:00
forget-junk
[ { } ] [
"IN: xabbabbja" eval "xabbabbja" vocab-files
] unit-test
[ "xabbabbja" forget-vocab ] with-compilation-unit
2007-09-20 18:09:08 -04:00
forget-junk