|
7 | 7 | T = el.Symbol('t') |
8 | 8 | NIL = el.Symbol('nil') |
9 | 9 |
|
10 | | -SYMBOLS = [T, NIL] + list(map(el.Symbol, ['foo', ':foo', 'bar'])) |
| 10 | +SYMBOLS = [T, NIL] + list(map(el.Symbol, ['foo', ':foo', '+'])) |
11 | 11 | LITERALS = list(map(el.Literal, [0, 1, -1, 0.0, 1.0, "foo", "bar", ""])) |
12 | 12 | CONS = [el.Cons(el.Literal(0), el.Literal(1)), el.Cons(el.Symbol('foo'), el.Literal('bar'))] |
13 | 13 | LISTS = list(map(el.List, [ |
|
16 | 16 | [el.Literal(s) for s in ['foo', 'bar', 'baz']], |
17 | 17 | ])) |
18 | 18 | QUOTES = [el.Quote(n) for l in [SYMBOLS, LITERALS, CONS, LISTS] for n in l[:2]] |
| 19 | +RAW = [el.Raw('(+ 1 2)'), el.Raw('(message "hello")')] |
19 | 20 |
|
20 | 21 | NODES = SYMBOLS + LITERALS + CONS + LISTS |
21 | 22 |
|
@@ -66,14 +67,76 @@ def test_convert(): |
66 | 67 |
|
67 | 68 | # Tuples to lists |
68 | 69 | tup = ((3.14, "bar", NIL, (1, 2))) |
69 | | - assert el.to_elisp(tup) == el.make_list(tup) |
| 70 | + assert el.to_elisp(tup) == el.List(list(map(el.to_elisp, tup))) |
| 71 | + |
| 72 | + # Lists become quoted |
| 73 | + assert el.to_elisp(list(tup)) == el.Quote(el.to_elisp(tup)) |
| 74 | + |
| 75 | + # Mapping objects converted as alists |
| 76 | + d = {'a': 1, 'b': 'foo', 'c': True} |
| 77 | + assert el.to_elisp(d) == el.make_alist(d) |
70 | 78 |
|
71 | 79 | # Should leave existing nodes unchanged |
72 | 80 | for n in NODES: |
73 | 81 | assert el.to_elisp(n) == n |
74 | 82 |
|
75 | 83 |
|
76 | | -def test_make_list(): |
77 | | - assert el.make_list((3.14, "bar", NIL, (1, 2))) == \ |
78 | | - el.List([el.Literal(3.14), el.Literal("bar"), NIL, |
79 | | - el.List([el.Literal(1), el.Literal(2)])]) |
| 84 | +def test_symbol_call(): |
| 85 | + """Test that calling a symbol creates a function call.""" |
| 86 | + assert el.Symbol('+')(1, 2) == el.List([el.Symbol('+'), 1, 2]) |
| 87 | + |
| 88 | + |
| 89 | +def test_str(): |
| 90 | + """Test conversion to str.""" |
| 91 | + assert list(map(str, SYMBOLS)) == ['t', 'nil', 'foo', ':foo', '+'] |
| 92 | + |
| 93 | + assert list(map(str, LITERALS)) == ['0', '1', '-1', '0.0', '1.0', '"foo"', '"bar"', '""'] |
| 94 | + |
| 95 | + assert str(el.List([1, el.Symbol('a'), "b"])) == '(1 a "b")' |
| 96 | + |
| 97 | + assert str(el.Cons(el.Symbol('a'), 1)) == '(cons a 1)' |
| 98 | + |
| 99 | + assert str(el.Quote(el.Symbol('foo'))) == '\'foo' |
| 100 | + assert str(el.Quote(el.List([1, el.Symbol('a'), "b"]))) == '\'(1 a "b")' |
| 101 | + assert str(el.Quote(el.Cons(el.Symbol('a'), 1))) == '\'(a . 1)' |
| 102 | + |
| 103 | + assert str(el.Raw('(+ 1 2)')) == '(+ 1 2)' |
| 104 | + |
| 105 | + |
| 106 | +def test_quote(): |
| 107 | + """Test quote() function.""" |
| 108 | + sym = el.Symbol('a') |
| 109 | + assert el.quote(sym) == el.Quote(sym) |
| 110 | + assert el.quote('a') == el.Quote(sym) |
| 111 | + |
| 112 | + l = el.List([1, 2, 3]) |
| 113 | + assert el.quote(l) == el.Quote(l) |
| 114 | + |
| 115 | + |
| 116 | +def test_symbols(): |
| 117 | + """Test the symbols() function.""" |
| 118 | + syms = el.symbols('a', 'b', 'c') |
| 119 | + assert syms == el.List(list(map(el.Symbol, 'abc'))) |
| 120 | + assert el.symbols('a', 'b', 'c', quote=True) == el.Quote(syms) |
| 121 | + |
| 122 | + |
| 123 | +def test_make_alist(): |
| 124 | + """Test the make_alist() function.""" |
| 125 | + d = {'a': 1, 'b': ('foo', el.Symbol('bar')), 42: True} |
| 126 | + assert el.make_alist(d) == el.List([ |
| 127 | + el.Cons(el.Symbol('a'), el.Literal(1)), |
| 128 | + el.Cons(el.Symbol('b'), el.to_elisp(d['b'])), |
| 129 | + el.Cons(el.Literal(42), el.Symbol('t')), |
| 130 | + ]) |
| 131 | + assert el.make_alist(d, quote=True) == el.Quote(el.make_alist(d)) |
| 132 | + |
| 133 | + |
| 134 | +def test_make_plist(): |
| 135 | + """Test the make_plist() function.""" |
| 136 | + d = {'a': "foo", 'b': (1, 2, 3), 'c': True} |
| 137 | + assert el.make_plist(d) == el.List([ |
| 138 | + el.Symbol('a'), el.Literal("foo"), |
| 139 | + el.Symbol('b'), el.to_elisp(d['b']), |
| 140 | + el.Symbol('c'), el.Symbol('t'), |
| 141 | + ]) |
| 142 | + assert el.make_plist(d, quote=True) == el.Quote(el.make_plist(d)) |
0 commit comments