syncraft 0.1.14__tar.gz → 0.1.15__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of syncraft might be problematic. Click here for more details.
- {syncraft-0.1.14 → syncraft-0.1.15}/PKG-INFO +1 -1
- {syncraft-0.1.14 → syncraft-0.1.15}/pyproject.toml +1 -1
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft.egg-info/PKG-INFO +1 -1
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft.egg-info/SOURCES.txt +1 -0
- syncraft-0.1.15/tests/test_bimap.py +88 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/LICENSE +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/README.md +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/setup.cfg +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft/__init__.py +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft/algebra.py +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft/ast.py +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft/cmd.py +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft/diagnostic.py +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft/dsl.py +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft/generator.py +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft/parser.py +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft/py.typed +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft/sqlite3.py +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft.egg-info/dependency_links.txt +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft.egg-info/requires.txt +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/syncraft.egg-info/top_level.txt +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/tests/test_parse.py +0 -0
- {syncraft-0.1.14 → syncraft-0.1.15}/tests/test_until.py +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from syncraft.parser import literal, variable, parse, Parser
|
|
3
|
+
from syncraft.ast import AST
|
|
4
|
+
import syncraft.generator as gen
|
|
5
|
+
from typing import Any
|
|
6
|
+
from rich import print
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test1_simple_then() -> None:
|
|
10
|
+
A, B, C = literal("a"), literal("b"), literal("c")
|
|
11
|
+
syntax = A // B // C
|
|
12
|
+
sql = "a b c"
|
|
13
|
+
ast = parse(syntax(Parser), sql, dialect="sqlite")
|
|
14
|
+
print("---" * 40)
|
|
15
|
+
print(ast)
|
|
16
|
+
generated = gen.generate(syntax(gen.Generator), ast)
|
|
17
|
+
print("---" * 40)
|
|
18
|
+
print(generated)
|
|
19
|
+
assert ast == generated
|
|
20
|
+
value, bmap = generated.bimap(None)
|
|
21
|
+
print(value)
|
|
22
|
+
assert bmap(value) == generated
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test2_named_results() -> None:
|
|
26
|
+
A, B = literal("a").bind("x").bind('z'), literal("b").bind("y")
|
|
27
|
+
syntax = A // B
|
|
28
|
+
sql = "a b"
|
|
29
|
+
ast = parse(syntax(Parser), sql, dialect="sqlite")
|
|
30
|
+
print("---" * 40)
|
|
31
|
+
print(ast)
|
|
32
|
+
generated = gen.generate(syntax(gen.Generator), ast)
|
|
33
|
+
print("---" * 40)
|
|
34
|
+
print(generated)
|
|
35
|
+
assert ast == generated
|
|
36
|
+
value, bmap = generated.bimap(None)
|
|
37
|
+
print(value)
|
|
38
|
+
print(bmap(value))
|
|
39
|
+
assert bmap(value) == generated
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test3_many_literals() -> None:
|
|
43
|
+
A = literal("a")
|
|
44
|
+
syntax = A.many()
|
|
45
|
+
sql = "a a a"
|
|
46
|
+
ast = parse(syntax(Parser), sql, dialect="sqlite")
|
|
47
|
+
print("---" * 40)
|
|
48
|
+
print(ast)
|
|
49
|
+
generated = gen.generate(syntax(gen.Generator), ast)
|
|
50
|
+
print("---" * 40)
|
|
51
|
+
print(generated)
|
|
52
|
+
assert ast == generated
|
|
53
|
+
value, bmap = generated.bimap(None)
|
|
54
|
+
print(value)
|
|
55
|
+
assert bmap(value) == generated
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test4_mixed_many_named() -> None:
|
|
59
|
+
A = literal("a").bind("x")
|
|
60
|
+
B = literal("b")
|
|
61
|
+
syntax = (A | B).many()
|
|
62
|
+
sql = "a b a"
|
|
63
|
+
ast = parse(syntax(Parser), sql, dialect="sqlite")
|
|
64
|
+
print("---" * 40)
|
|
65
|
+
print(ast)
|
|
66
|
+
generated = gen.generate(syntax(gen.Generator), ast)
|
|
67
|
+
print("---" * 40)
|
|
68
|
+
print(generated)
|
|
69
|
+
assert ast == generated
|
|
70
|
+
value, bmap = generated.bimap(None)
|
|
71
|
+
print(value)
|
|
72
|
+
assert bmap(value) == generated
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test5_nested_then_many() -> None:
|
|
76
|
+
IF, THEN, END = literal("if"), literal("then"), literal("end")
|
|
77
|
+
syntax = (IF.many() // THEN.many()).many() // END
|
|
78
|
+
sql = "if if then end"
|
|
79
|
+
ast = parse(syntax(Parser), sql, dialect="sqlite")
|
|
80
|
+
print("---" * 40)
|
|
81
|
+
print(ast)
|
|
82
|
+
generated = gen.generate(syntax(gen.Generator), ast)
|
|
83
|
+
print("---" * 40)
|
|
84
|
+
print(generated)
|
|
85
|
+
# assert ast == generated
|
|
86
|
+
value, bmap = generated.bimap(None)
|
|
87
|
+
print(value)
|
|
88
|
+
assert bmap(value) == generated
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|