factor/extra/peg/ebnf/ebnf-tests.factor

118 lines
2.3 KiB
Factor
Raw Normal View History

2007-11-27 00:13:36 -05:00
! Copyright (C) 2007 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
!
USING: kernel tools.test peg peg.ebnf ;
2008-03-01 17:00:45 -05:00
IN: peg.ebnf.tests
2007-11-27 00:13:36 -05:00
{ T{ ebnf-non-terminal f "abc" } } [
"abc" 'non-terminal' parse parse-result-ast
] unit-test
{ T{ ebnf-terminal f "55" } } [
2007-11-27 19:05:53 -05:00
"'55'" 'terminal' parse parse-result-ast
2007-11-27 00:13:36 -05:00
] unit-test
2007-11-27 16:28:28 -05:00
{
T{ ebnf-rule f
2007-11-27 19:05:53 -05:00
"digit"
V{
T{ ebnf-choice f
V{ T{ ebnf-terminal f "1" } T{ ebnf-terminal f "2" } }
}
f
2007-11-27 16:28:28 -05:00
}
}
} [
2007-11-27 19:05:53 -05:00
"digit = '1' | '2'" 'rule' parse parse-result-ast
2007-11-27 16:28:28 -05:00
] unit-test
{
T{ ebnf-rule f
"digit"
2007-11-27 19:05:53 -05:00
V{
T{ ebnf-sequence f
V{ T{ ebnf-terminal f "1" } T{ ebnf-terminal f "2" } }
}
f
2007-11-27 16:28:28 -05:00
}
2007-11-27 19:05:53 -05:00
}
2007-11-27 16:28:28 -05:00
} [
2007-11-27 19:05:53 -05:00
"digit = '1' '2'" 'rule' parse parse-result-ast
] unit-test
{
T{ ebnf-choice f
V{
T{ ebnf-sequence f
V{ T{ ebnf-non-terminal f "one" } T{ ebnf-non-terminal f "two" } }
}
T{ ebnf-non-terminal f "three" }
}
}
} [
"one two | three" 'choice' parse parse-result-ast
2007-11-27 21:26:25 -05:00
] unit-test
{
T{ ebnf-sequence f
V{
T{ ebnf-non-terminal f "one" }
T{ ebnf-choice f
V{ T{ ebnf-non-terminal f "two" } T{ ebnf-non-terminal f "three" } }
}
}
}
} [
"one (two | three)" 'choice' parse parse-result-ast
2007-11-27 21:32:04 -05:00
] unit-test
{
T{ ebnf-sequence f
V{
T{ ebnf-non-terminal f "one" }
T{ ebnf-repeat0 f
T{ ebnf-sequence f
V{
T{ ebnf-choice f
V{ T{ ebnf-non-terminal f "two" } T{ ebnf-non-terminal f "three" } }
}
T{ ebnf-non-terminal f "four" }
}
}
}
}
}
} [
"one ((two | three) four)*" 'choice' parse parse-result-ast
2007-11-27 21:49:14 -05:00
] unit-test
{
T{ ebnf-sequence f
V{
T{ ebnf-non-terminal f "one" }
T{ ebnf-optional f T{ ebnf-non-terminal f "two" } }
T{ ebnf-non-terminal f "three" }
}
}
} [
"one ( two )? three" 'choice' parse parse-result-ast
2007-11-27 21:49:14 -05:00
] unit-test
2008-03-19 00:34:28 -04:00
{ "foo" } [
"\"foo\"" 'identifier' parse parse-result-ast
] unit-test
{ "foo" } [
"'foo'" 'identifier' parse parse-result-ast
] unit-test
{ "foo" } [
"foo" 'non-terminal' parse parse-result-ast ebnf-non-terminal-symbol
] unit-test
{ "foo" } [
"foo]" 'non-terminal' parse parse-result-ast ebnf-non-terminal-symbol
] unit-test