testASPLang.jl
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using Test
include("ASPLang.jl")
using .ASPLang
@testset "invalid term" begin
@test_throws "" parse_asp("", term_grammar)
@test_throws "" parse_asp("1+", term_grammar)
@test_throws "" parse_asp("()", term_grammar)
@test_throws "" parse_asp("(", term_grammar)
@test_throws "" parse_asp(")", term_grammar)
@test_throws "" parse_asp("[]", term_grammar)
@test_throws "" parse_asp("[", term_grammar)
@test_throws "" parse_asp("]", term_grammar)
@test_throws "" parse_asp("{}", term_grammar)
@test_throws "" parse_asp("{", term_grammar)
@test_throws "" parse_asp("}", term_grammar)
@test_throws "" parse_asp("1+()", term_grammar)
@test_throws "" parse_asp("1<2", term_grammar)
@test_throws "" parse_asp("1a", term_grammar)
@test_throws "" parse_asp("1+(a+", term_grammar)
@test_throws "" parse_asp("1+(1+))", term_grammar)
@test_throws "" parse_asp("(1+(1)()", term_grammar)
end
@testset "variable" begin
@test parse_asp("A", term_grammar) == Variable("A")
@test parse_asp("A_a1b_2", term_grammar) == Variable("A_a1b_2")
@test parse_asp("a", term_grammar) != Variable("a")
@test_throws "" parse_asp("", term_grammar) != Variable("")
end
@testset "string constant" begin
@test parse_asp("\"\"", term_grammar) == StringConstant("")
@test parse_asp("\"A\"", term_grammar) == StringConstant("A")
@test parse_asp("\"a\"", term_grammar) == StringConstant("a")
@test parse_asp("\"1\"", term_grammar) == StringConstant("1")
@test parse_asp("\"A_a1b_2\"", term_grammar) == StringConstant("A_a1b_2")
end
@testset "symbolic constant" begin
@test parse_asp("a", term_grammar) == SymbolicConstant("a")
@test parse_asp("a_A1B_2", term_grammar) == SymbolicConstant("a_A1B_2")
@test parse_asp("A", term_grammar) != SymbolicConstant("A")
end