@voxgig/sdkgen 1.3.17 → 1.3.18

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.
Files changed (220) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/Entity.js +5 -1
  3. package/dist/cmp/Entity.js.map +1 -1
  4. package/dist/cmp/Feature.js +2 -1
  5. package/dist/cmp/Feature.js.map +1 -1
  6. package/dist/helpers/canonType.js +8 -3
  7. package/dist/helpers/canonType.js.map +1 -1
  8. package/dist/helpers/collectDeps.d.ts +1 -1
  9. package/dist/helpers/collectDeps.js +36 -13
  10. package/dist/helpers/collectDeps.js.map +1 -1
  11. package/dist/helpers/naming.d.ts +3 -1
  12. package/dist/helpers/naming.js +53 -0
  13. package/dist/helpers/naming.js.map +1 -1
  14. package/dist/helpers/opShape.d.ts +3 -1
  15. package/dist/helpers/opShape.js +87 -8
  16. package/dist/helpers/opShape.js.map +1 -1
  17. package/dist/sdkgen.d.ts +3 -3
  18. package/dist/sdkgen.js +6 -2
  19. package/dist/sdkgen.js.map +1 -1
  20. package/dist/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +15 -10
  22. package/project/.sdk/model/target/cpp.aontu +4 -4
  23. package/project/.sdk/model/target/go-cli.aontu +17 -17
  24. package/project/.sdk/model/target/go-mcp.aontu +11 -11
  25. package/project/.sdk/model/target/go.aontu +1 -1
  26. package/project/.sdk/model/target/java.aontu +4 -4
  27. package/project/.sdk/model/target/kotlin.aontu +4 -4
  28. package/project/.sdk/model/target/lean.aontu +51 -0
  29. package/project/.sdk/model/target/scala.aontu +4 -4
  30. package/project/.sdk/src/cmp/c/EntityTypes_c.ts +3 -4
  31. package/project/.sdk/src/cmp/c/Entity_c.ts +3 -3
  32. package/project/.sdk/src/cmp/c/ReadmeExamplesTest_c.ts +24 -7
  33. package/project/.sdk/src/cmp/c/TestDirect_c.ts +3 -3
  34. package/project/.sdk/src/cmp/c/TestEntity_c.ts +1 -1
  35. package/project/.sdk/src/cmp/clojure/Entity_clojure.ts +1 -1
  36. package/project/.sdk/src/cmp/clojure/ReadmeExamplesTest_clojure.ts +19 -8
  37. package/project/.sdk/src/cmp/cpp/EntityTypes_cpp.ts +2 -2
  38. package/project/.sdk/src/cmp/cpp/Entity_cpp.ts +3 -3
  39. package/project/.sdk/src/cmp/cpp/MainEntity_cpp.ts +2 -2
  40. package/project/.sdk/src/cmp/cpp/ReadmeExamplesTest_cpp.ts +136 -0
  41. package/project/.sdk/src/cmp/cpp/TestDirect_cpp.ts +3 -3
  42. package/project/.sdk/src/cmp/cpp/Test_cpp.ts +4 -0
  43. package/project/.sdk/src/cmp/csharp/EntityTypes_csharp.ts +2 -3
  44. package/project/.sdk/src/cmp/csharp/Entity_csharp.ts +3 -3
  45. package/project/.sdk/src/cmp/csharp/MainEntity_csharp.ts +2 -2
  46. package/project/.sdk/src/cmp/csharp/Package_csharp.ts +1 -1
  47. package/project/.sdk/src/cmp/csharp/ReadmeExamplesTest_csharp.ts +13 -1
  48. package/project/.sdk/src/cmp/csharp/TestDirect_csharp.ts +3 -3
  49. package/project/.sdk/src/cmp/dart/EntityTypes_dart.ts +2 -3
  50. package/project/.sdk/src/cmp/dart/Entity_dart.ts +3 -3
  51. package/project/.sdk/src/cmp/dart/MainEntity_dart.ts +2 -2
  52. package/project/.sdk/src/cmp/dart/Main_dart.ts +3 -3
  53. package/project/.sdk/src/cmp/dart/Package_dart.ts +1 -1
  54. package/project/.sdk/src/cmp/dart/TestDirect_dart.ts +4 -4
  55. package/project/.sdk/src/cmp/elixir/EntityTypes_elixir.ts +2 -3
  56. package/project/.sdk/src/cmp/elixir/Entity_elixir.ts +1 -1
  57. package/project/.sdk/src/cmp/elixir/ReadmeExamplesTest_elixir.ts +21 -3
  58. package/project/.sdk/src/cmp/go/Config_go.ts +4 -1
  59. package/project/.sdk/src/cmp/go/EntityTypes_go.ts +110 -18
  60. package/project/.sdk/src/cmp/go/Entity_go.ts +3 -3
  61. package/project/.sdk/src/cmp/go/Main_go.ts +7 -6
  62. package/project/.sdk/src/cmp/go/Package_go.ts +1 -1
  63. package/project/.sdk/src/cmp/go/TestDirect_go.ts +3 -3
  64. package/project/.sdk/src/cmp/go/TestEntity_go.ts +1 -1
  65. package/project/.sdk/src/cmp/go/utility_go.ts +25 -0
  66. package/project/.sdk/src/cmp/go-cli/Main_go-cli.ts +9 -1
  67. package/project/.sdk/src/cmp/go-mcp/Main_go-mcp.ts +9 -1
  68. package/project/.sdk/src/cmp/haskell/ReadmeExamplesTest_haskell.ts +28 -18
  69. package/project/.sdk/src/cmp/java/EntityTypes_java.ts +2 -3
  70. package/project/.sdk/src/cmp/java/Entity_java.ts +3 -3
  71. package/project/.sdk/src/cmp/java/MainEntity_java.ts +2 -2
  72. package/project/.sdk/src/cmp/java/Package_java.ts +1 -1
  73. package/project/.sdk/src/cmp/java/ReadmeExamplesTest_java.ts +23 -1
  74. package/project/.sdk/src/cmp/java/TestDirect_java.ts +3 -3
  75. package/project/.sdk/src/cmp/js/EntityTypes_js.ts +2 -3
  76. package/project/.sdk/src/cmp/js/Entity_js.ts +3 -3
  77. package/project/.sdk/src/cmp/js/MainEntity_js.ts +2 -2
  78. package/project/.sdk/src/cmp/js/Main_js.ts +2 -2
  79. package/project/.sdk/src/cmp/js/TestDirect_js.ts +4 -4
  80. package/project/.sdk/src/cmp/kotlin/EntityTypes_kotlin.ts +2 -3
  81. package/project/.sdk/src/cmp/kotlin/Entity_kotlin.ts +3 -3
  82. package/project/.sdk/src/cmp/kotlin/MainEntity_kotlin.ts +2 -2
  83. package/project/.sdk/src/cmp/kotlin/Package_kotlin.ts +1 -1
  84. package/project/.sdk/src/cmp/kotlin/ReadmeExamplesTest_kotlin.ts +27 -2
  85. package/project/.sdk/src/cmp/kotlin/TestDirect_kotlin.ts +3 -3
  86. package/project/.sdk/src/cmp/lean/Config_lean.ts +88 -0
  87. package/project/.sdk/src/cmp/lean/Entity_lean.ts +9 -0
  88. package/project/.sdk/src/cmp/lean/Gitignore_lean.ts +18 -0
  89. package/project/.sdk/src/cmp/lean/Main_lean.ts +120 -0
  90. package/project/.sdk/src/cmp/lean/Package_lean.ts +68 -0
  91. package/project/.sdk/src/cmp/lean/ReadmeEntity_lean.ts +29 -0
  92. package/project/.sdk/src/cmp/lean/ReadmeExplanation_lean.ts +19 -0
  93. package/project/.sdk/src/cmp/lean/ReadmeHowto_lean.ts +25 -0
  94. package/project/.sdk/src/cmp/lean/ReadmeInstall_lean.ts +38 -0
  95. package/project/.sdk/src/cmp/lean/ReadmeIntro_lean.ts +25 -0
  96. package/project/.sdk/src/cmp/lean/ReadmeModel_lean.ts +24 -0
  97. package/project/.sdk/src/cmp/lean/ReadmeOptions_lean.ts +22 -0
  98. package/project/.sdk/src/cmp/lean/ReadmeQuick_lean.ts +50 -0
  99. package/project/.sdk/src/cmp/lean/ReadmeRef_lean.ts +16 -0
  100. package/project/.sdk/src/cmp/lean/ReadmeTopHowto_lean.ts +16 -0
  101. package/project/.sdk/src/cmp/lean/ReadmeTopQuick_lean.ts +23 -0
  102. package/project/.sdk/src/cmp/lean/ReadmeTopTest_lean.ts +18 -0
  103. package/project/.sdk/src/cmp/lean/Test_lean.ts +207 -0
  104. package/project/.sdk/src/cmp/lean/utility_lean.ts +78 -0
  105. package/project/.sdk/src/cmp/lua/EntityTypes_lua.ts +2 -3
  106. package/project/.sdk/src/cmp/lua/Entity_lua.ts +3 -3
  107. package/project/.sdk/src/cmp/lua/Package_lua.ts +1 -1
  108. package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +3 -3
  109. package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +1 -1
  110. package/project/.sdk/src/cmp/ocaml/ReadmeExamplesTest_ocaml.ts +29 -14
  111. package/project/.sdk/src/cmp/perl/Entity_perl.ts +3 -3
  112. package/project/.sdk/src/cmp/perl/MainEntity_perl.ts +2 -2
  113. package/project/.sdk/src/cmp/perl/Package_perl.ts +1 -1
  114. package/project/.sdk/src/cmp/perl/TestDirect_perl.ts +3 -3
  115. package/project/.sdk/src/cmp/php/EntityTypes_php.ts +2 -3
  116. package/project/.sdk/src/cmp/php/Entity_php.ts +3 -3
  117. package/project/.sdk/src/cmp/php/MainEntity_php.ts +2 -2
  118. package/project/.sdk/src/cmp/php/Package_php.ts +1 -1
  119. package/project/.sdk/src/cmp/php/TestDirect_php.ts +3 -3
  120. package/project/.sdk/src/cmp/php/TestEntity_php.ts +1 -1
  121. package/project/.sdk/src/cmp/py/EntityTypes_py.ts +2 -3
  122. package/project/.sdk/src/cmp/py/Entity_py.ts +3 -3
  123. package/project/.sdk/src/cmp/py/MainEntity_py.ts +2 -2
  124. package/project/.sdk/src/cmp/py/Main_py.ts +2 -2
  125. package/project/.sdk/src/cmp/py/Package_py.ts +1 -1
  126. package/project/.sdk/src/cmp/py/TestDirect_py.ts +3 -3
  127. package/project/.sdk/src/cmp/py/TestEntity_py.ts +1 -1
  128. package/project/.sdk/src/cmp/rb/EntityTypes_rb.ts +15 -5
  129. package/project/.sdk/src/cmp/rb/Entity_rb.ts +3 -3
  130. package/project/.sdk/src/cmp/rb/MainEntity_rb.ts +2 -2
  131. package/project/.sdk/src/cmp/rb/Package_rb.ts +2 -2
  132. package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +3 -3
  133. package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +1 -1
  134. package/project/.sdk/src/cmp/rust/EntityBase_rust.ts +2 -2
  135. package/project/.sdk/src/cmp/rust/EntityTypes_rust.ts +3 -4
  136. package/project/.sdk/src/cmp/rust/Entity_rust.ts +3 -3
  137. package/project/.sdk/src/cmp/rust/MainEntity_rust.ts +2 -2
  138. package/project/.sdk/src/cmp/rust/Package_rust.ts +1 -1
  139. package/project/.sdk/src/cmp/rust/ReadmeExamplesTest_rust.ts +22 -10
  140. package/project/.sdk/src/cmp/rust/TestDirect_rust.ts +3 -3
  141. package/project/.sdk/src/cmp/scala/EntityTypes_scala.ts +2 -3
  142. package/project/.sdk/src/cmp/scala/Entity_scala.ts +3 -3
  143. package/project/.sdk/src/cmp/scala/MainEntity_scala.ts +2 -2
  144. package/project/.sdk/src/cmp/scala/ReadmeExamplesTest_scala.ts +22 -3
  145. package/project/.sdk/src/cmp/scala/TestDirect_scala.ts +3 -3
  146. package/project/.sdk/src/cmp/scala/Test_scala.ts +1 -1
  147. package/project/.sdk/src/cmp/swift/EntityTypes_swift.ts +3 -4
  148. package/project/.sdk/src/cmp/swift/Entity_swift.ts +3 -3
  149. package/project/.sdk/src/cmp/swift/MainEntity_swift.ts +2 -2
  150. package/project/.sdk/src/cmp/swift/Package_swift.ts +1 -1
  151. package/project/.sdk/src/cmp/swift/ReadmeExamplesTest_swift.ts +18 -1
  152. package/project/.sdk/src/cmp/swift/TestDirect_swift.ts +1 -1
  153. package/project/.sdk/src/cmp/ts/EntityTypes_ts.ts +2 -3
  154. package/project/.sdk/src/cmp/ts/Entity_ts.ts +3 -3
  155. package/project/.sdk/src/cmp/ts/MainEntity_ts.ts +2 -2
  156. package/project/.sdk/src/cmp/ts/Main_ts.ts +2 -2
  157. package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +4 -4
  158. package/project/.sdk/src/cmp/zig/Entity_zig.ts +3 -3
  159. package/project/.sdk/src/cmp/zig/MainEntity_zig.ts +2 -2
  160. package/project/.sdk/src/cmp/zig/Package_zig.ts +10 -2
  161. package/project/.sdk/tm/cpp/test/primary_utility_test.cpp +8 -16
  162. package/project/.sdk/tm/csharp/test/PrimaryUtilityTest.cs +10 -28
  163. package/project/.sdk/tm/dart/test/primary_test.dart +7 -0
  164. package/project/.sdk/tm/go/feature/test_feature.go +33 -1
  165. package/project/.sdk/tm/go/test/primary_utility_test.go +41 -42
  166. package/project/.sdk/tm/go/test/runner_test.go +30 -1
  167. package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +7 -24
  168. package/project/.sdk/tm/js/src/feature/test/TestFeature.js +18 -1
  169. package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +8 -0
  170. package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +7 -20
  171. package/project/.sdk/tm/lean/LICENSE +21 -0
  172. package/project/.sdk/tm/lean/VERSION +1 -0
  173. package/project/.sdk/tm/lean/src/SdkFeature.lean +171 -0
  174. package/project/.sdk/tm/lean/src/SdkFeatures.lean +602 -0
  175. package/project/.sdk/tm/lean/src/SdkJson.lean +134 -0
  176. package/project/.sdk/tm/lean/src/SdkRuntime.lean +356 -0
  177. package/project/.sdk/tm/lean/src/SdkUtility.lean +617 -0
  178. package/project/.sdk/tm/lean/src/VoxgigStruct.lean +2880 -0
  179. package/project/.sdk/tm/lean/src/Vregex.lean +412 -0
  180. package/project/.sdk/tm/lean/src/feature/README.md +5 -0
  181. package/project/.sdk/tm/lean/src/feature/audit/.gitkeep +0 -0
  182. package/project/.sdk/tm/lean/src/feature/base/.gitkeep +0 -0
  183. package/project/.sdk/tm/lean/src/feature/cache/.gitkeep +0 -0
  184. package/project/.sdk/tm/lean/src/feature/clienttrack/.gitkeep +0 -0
  185. package/project/.sdk/tm/lean/src/feature/debug/.gitkeep +0 -0
  186. package/project/.sdk/tm/lean/src/feature/idempotency/.gitkeep +0 -0
  187. package/project/.sdk/tm/lean/src/feature/log/.gitkeep +0 -0
  188. package/project/.sdk/tm/lean/src/feature/metrics/.gitkeep +0 -0
  189. package/project/.sdk/tm/lean/src/feature/netsim/.gitkeep +0 -0
  190. package/project/.sdk/tm/lean/src/feature/paging/.gitkeep +0 -0
  191. package/project/.sdk/tm/lean/src/feature/proxy/.gitkeep +0 -0
  192. package/project/.sdk/tm/lean/src/feature/ratelimit/.gitkeep +0 -0
  193. package/project/.sdk/tm/lean/src/feature/rbac/.gitkeep +0 -0
  194. package/project/.sdk/tm/lean/src/feature/retry/.gitkeep +0 -0
  195. package/project/.sdk/tm/lean/src/feature/streaming/.gitkeep +0 -0
  196. package/project/.sdk/tm/lean/src/feature/telemetry/.gitkeep +0 -0
  197. package/project/.sdk/tm/lean/src/feature/test/.gitkeep +0 -0
  198. package/project/.sdk/tm/lean/src/feature/timeout/.gitkeep +0 -0
  199. package/project/.sdk/tm/lean/test/StructCorpus.lean +697 -0
  200. package/project/.sdk/tm/lean/test/TFeature.lean +268 -0
  201. package/project/.sdk/tm/lean/test/TPrimaryUtility.lean +349 -0
  202. package/project/.sdk/tm/lua/test/primary_utility_test.lua +10 -8
  203. package/project/.sdk/tm/perl/t/primary_utility.t +8 -17
  204. package/project/.sdk/tm/php/test/PrimaryUtilityTest.php +9 -7
  205. package/project/.sdk/tm/py/feature/test_feature.py +28 -1
  206. package/project/.sdk/tm/py/test/test_primary_utility.py +13 -18
  207. package/project/.sdk/tm/rb/feature/test_feature.rb +24 -1
  208. package/project/.sdk/tm/rb/test/primary_utility_test.rb +7 -8
  209. package/project/.sdk/tm/rust/tests/common/mod.rs +37 -1
  210. package/project/.sdk/tm/rust/tests/primary_utility_test.rs +12 -26
  211. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/PrimaryUtilityTest.swift +7 -8
  212. package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +18 -1
  213. package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +65 -21
  214. package/src/cmp/Entity.ts +5 -1
  215. package/src/cmp/Feature.ts +2 -1
  216. package/src/helpers/canonType.ts +8 -3
  217. package/src/helpers/collectDeps.ts +39 -12
  218. package/src/helpers/naming.ts +59 -0
  219. package/src/helpers/opShape.ts +99 -12
  220. package/src/sdkgen.ts +7 -3
@@ -0,0 +1,697 @@
1
+ /- Struct corpus runner: drives the `struct` subtree of the shared
2
+ ../.sdk/test/test.json (the project's own compiled corpus, same file the
3
+ other targets read) against the vendored voxgig-struct port.
4
+ Self-contained: an in-tree JSON reader builds the library's `Value` type
5
+ directly, so the Lean port is exercised exactly as in production. -/
6
+
7
+ import VoxgigStruct
8
+
9
+ open VoxgigStruct
10
+
11
+ def nullmark : String := "__NULL__"
12
+ def undefmark : String := "__UNDEF__"
13
+ def existsmark : String := "__EXISTS__"
14
+
15
+ -- ---------------- JSON reader -> Value ----------------
16
+
17
+ structure JState where
18
+ src : Array Char
19
+ pos : Nat
20
+
21
+ partial def jPeek (s : JState) : Option Char := s.src[s.pos]?
22
+
23
+ partial def jSkipWs (s : JState) : JState := Id.run do
24
+ let mut p := s.pos
25
+ while p < s.src.size &&
26
+ (s.src[p]! == ' ' || s.src[p]! == '\t' || s.src[p]! == '\n' || s.src[p]! == '\r') do
27
+ p := p + 1
28
+ return { s with pos := p }
29
+
30
+ partial def jStr (s0 : JState) : SIO (String × JState) := do
31
+ -- assumes current char is '"'
32
+ let src := s0.src
33
+ let mut p := s0.pos + 1
34
+ let mut b := ""
35
+ repeat do
36
+ if p >= src.size then break
37
+ let c := src[p]!
38
+ p := p + 1
39
+ if c == '"' then break
40
+ if c == '\\' then
41
+ let e := src[p]!
42
+ p := p + 1
43
+ match e with
44
+ | '"' => b := b.push '"'
45
+ | '\\' => b := b.push '\\'
46
+ | '/' => b := b.push '/'
47
+ | 'n' => b := b.push '\n'
48
+ | 't' => b := b.push '\t'
49
+ | 'r' => b := b.push '\r'
50
+ | 'b' => b := b.push '\x08'
51
+ | 'f' => b := b.push '\x0c'
52
+ | 'u' => do
53
+ let mut code : Nat := 0
54
+ for _ in [0:4] do
55
+ let h := src[p]!
56
+ p := p + 1
57
+ let d :=
58
+ if h >= '0' && h <= '9' then h.toNat - '0'.toNat
59
+ else if h >= 'a' && h <= 'f' then 10 + h.toNat - 'a'.toNat
60
+ else if h >= 'A' && h <= 'F' then 10 + h.toNat - 'A'.toNat
61
+ else 0
62
+ code := code * 16 + d
63
+ b := b.push (Char.ofNat code)
64
+ | c => b := b.push c
65
+ else
66
+ b := b.push c
67
+ return (b, { s0 with pos := p })
68
+
69
+ mutual
70
+
71
+ partial def jVal (s0 : JState) : SIO (Value × JState) := do
72
+ let s := jSkipWs s0
73
+ match jPeek s with
74
+ | some '{' => jObj s
75
+ | some '[' => jArr s
76
+ | some '"' => do
77
+ let (str, s') ← jStr s
78
+ pure (.str str, s')
79
+ | some 't' => pure (.bool true, { s with pos := s.pos + 4 })
80
+ | some 'f' => pure (.bool false, { s with pos := s.pos + 5 })
81
+ | some 'n' => pure (.null, { s with pos := s.pos + 4 })
82
+ | _ => jNum s
83
+
84
+ partial def jObj (s0 : JState) : SIO (Value × JState) := do
85
+ let s := jSkipWs { s0 with pos := s0.pos + 1 }
86
+ if jPeek s == some '}' then
87
+ pure (← emptyMap, { s with pos := s.pos + 1 })
88
+ else do
89
+ let m ← emptyMap
90
+ let sRef ← IO.mkRef s
91
+ repeat do
92
+ let s1 := jSkipWs (← sRef.get)
93
+ let (k, s2) ← jStr s1
94
+ let s3 := jSkipWs s2
95
+ let s4 := { s3 with pos := s3.pos + 1 } -- ':'
96
+ let (v, s5) ← jVal s4
97
+ let _ ← setprop m (.str k) v
98
+ let s6 := jSkipWs s5
99
+ let c := (jPeek s6).getD '}'
100
+ sRef.set { s6 with pos := s6.pos + 1 }
101
+ if c != ',' then break
102
+ pure (m, ← sRef.get)
103
+
104
+ partial def jArr (s0 : JState) : SIO (Value × JState) := do
105
+ let s := jSkipWs { s0 with pos := s0.pos + 1 }
106
+ if jPeek s == some ']' then
107
+ pure (← emptyList, { s with pos := s.pos + 1 })
108
+ else do
109
+ let sRef ← IO.mkRef s
110
+ let accRef ← IO.mkRef (#[] : Array Value)
111
+ repeat do
112
+ let (v, s1) ← jVal (← sRef.get)
113
+ accRef.modify (·.push v)
114
+ let s2 := jSkipWs s1
115
+ let c := (jPeek s2).getD ']'
116
+ sRef.set { s2 with pos := s2.pos + 1 }
117
+ if c != ',' then break
118
+ pure (← newList (← accRef.get), ← sRef.get)
119
+
120
+ partial def jNum (s0 : JState) : SIO (Value × JState) := do
121
+ let src := s0.src
122
+ let mut p := s0.pos
123
+ let start := p
124
+ while p < src.size &&
125
+ (let c := src[p]!
126
+ (c >= '0' && c <= '9') || c == '-' || c == '+' || c == '.' || c == 'e' || c == 'E') do
127
+ p := p + 1
128
+ let tok := String.ofList (src.extract start p).toList
129
+ pure (.num ((parseFloatJS tok).getD 0.0), { s0 with pos := p })
130
+
131
+ end
132
+
133
+ def jsonRead (s : String) : SIO Value := do
134
+ pure (← jVal { src := s.toList.toArray, pos := 0 }).1
135
+
136
+ -- ---------------- fixJSON / equality ----------------
137
+
138
+ partial def fixJson (v : Value) (flagNull : Bool) : SIO Value := do
139
+ match v with
140
+ | .noval | .null => if flagNull then pure (.str nullmark) else pure v
141
+ | .map id => do
142
+ let o ← emptyMap
143
+ for (k, x) in (← mapEntries id) do
144
+ let _ ← setprop o (.str k) (← fixJson x flagNull)
145
+ pure o
146
+ | .list id => do
147
+ let mut out : Array Value := #[]
148
+ for x in (← listItems id) do
149
+ out := out.push (← fixJson x flagNull)
150
+ newList out
151
+ | _ => pure v
152
+
153
+ /-- Order-independent deep equality for maps; sequence equality for lists. -/
154
+ partial def eqv (a b : Value) : SIO Bool := do
155
+ match a, b with
156
+ | .noval, .noval | .noval, .null | .null, .noval | .null, .null => pure true
157
+ | .bool x, .bool y => pure (x == y)
158
+ | .num x, .num y => pure (x == y)
159
+ | .str x, .str y => pure (x == y)
160
+ | .list x, .list y => do
161
+ let xs ← listItems x
162
+ let ys ← listItems y
163
+ if xs.size != ys.size then pure false
164
+ else do
165
+ for i in [0:xs.size] do
166
+ if !(← eqv xs[i]! ys[i]!) then return false
167
+ pure true
168
+ | .map x, .map y => do
169
+ let xes ← mapEntries x
170
+ let yes ← mapEntries y
171
+ if xes.size != yes.size then pure false
172
+ else do
173
+ for (k, v) in xes do
174
+ match omapGet yes k with
175
+ | some w =>
176
+ if !(← eqv v w) then return false
177
+ | none => return false
178
+ pure true
179
+ | _, _ => pure (a == b)
180
+
181
+ -- ---------------- match support ----------------
182
+
183
+ def strContainsSub (hay needle : String) : Bool := Id.run do
184
+ let h := hay.toList.toArray
185
+ let nd := needle.toList.toArray
186
+ if nd.size == 0 then return true
187
+ if nd.size > h.size then return false
188
+ for i in [0:h.size - nd.size + 1] do
189
+ let mut ok := true
190
+ for j in [0:nd.size] do
191
+ if h[i + j]! != nd[j]! then ok := false
192
+ if ok then return true
193
+ return false
194
+
195
+ partial def matchval (check0 base : Value) : SIO Bool := do
196
+ let check := if check0 == .str undefmark || check0 == .str nullmark then Value.noval
197
+ else check0
198
+ if ← eqv check base then pure true
199
+ else match check with
200
+ | .str cs => do
201
+ let basestr ← stringify base
202
+ let csArr := cs.toList.toArray
203
+ if csArr.size >= 2 && csArr[0]! == '/' && csArr[csArr.size - 1]! == '/' then
204
+ pure (Vregex.testStr (String.ofList (csArr.extract 1 (csArr.size - 1)).toList) basestr)
205
+ else
206
+ pure (strContainsSub basestr.toLower (← stringify check).toLower)
207
+ | .func _ => pure true
208
+ | _ => pure false
209
+
210
+ partial def doMatch (check base0 : Value) : SIO Unit := do
211
+ let base ← clone base0
212
+ let _ ← walk check (before := some (fun _k v _p path => do
213
+ if !(isnode v) then do
214
+ let baseval ← getpath base path
215
+ if ← eqv baseval v then pure ()
216
+ else if v == .str undefmark && isNullish baseval then pure ()
217
+ else if v == .str existsmark && !(isNullish baseval) then pure ()
218
+ else if !(← matchval v baseval) then do
219
+ let mut parts : List String := []
220
+ for x in (← listItemsOf path) do
221
+ parts := (← jsString x) :: parts
222
+ throw (IO.userError ("MATCH: " ++ String.intercalate "." parts.reverse
223
+ ++ ": [" ++ (← stringify v) ++ "] <=> [" ++ (← stringify baseval) ++ "]"))
224
+ pure v))
225
+ pure ()
226
+
227
+ -- ---------------- result tracking ----------------
228
+
229
+ initialize npass : IO.Ref Nat ← IO.mkRef 0
230
+ initialize nfail : IO.Ref Nat ← IO.mkRef 0
231
+ initialize failures : IO.Ref (List String) ← IO.mkRef []
232
+
233
+ def record (group name : String) (ok : Bool) (msg : String) : IO Unit := do
234
+ if ok then npass.modify (· + 1)
235
+ else do
236
+ nfail.modify (· + 1)
237
+ failures.modify (("FAIL " ++ group ++ " " ++ name ++ " - " ++ msg) :: ·)
238
+
239
+ -- ---------------- per-entry runner ----------------
240
+
241
+ def omapV (kvs : List (String × Value)) : SIO Value := do
242
+ let m ← emptyMap
243
+ for (k, v) in kvs do
244
+ let _ ← setprop m (.str k) v
245
+ pure m
246
+
247
+ def entryGet (e : Value) (k : String) : SIO Value := do
248
+ match e with
249
+ | .map id => pure ((omapGet (← mapEntries id) k).getD .noval)
250
+ | _ => pure .noval
251
+
252
+ def entryHas (e : Value) (k : String) : SIO Bool := do
253
+ match e with
254
+ | .map id => pure (omapHas (← mapEntries id) k)
255
+ | _ => pure false
256
+
257
+ def resolveArgs (entry : Value) : SIO (List Value) := do
258
+ if ← entryHas entry "ctx" then pure [← entryGet entry "ctx"]
259
+ else if ← entryHas entry "args" then pure (← listItemsOf (← entryGet entry "args")).toList
260
+ else if ← entryHas entry "in" then pure [← clone (← entryGet entry "in")]
261
+ else pure [.noval]
262
+
263
+ def checkResult (entry : Value) (args : List Value) (res : Value) : SIO Unit := do
264
+ let mut matched := false
265
+ if ← entryHas entry "match" then do
266
+ doMatch (← entryGet entry "match")
267
+ (← omapV [("in", ← entryGet entry "in"), ("args", ← newList args.toArray),
268
+ ("out", ← entryGet entry "res"), ("ctx", ← entryGet entry "ctx")])
269
+ matched := true
270
+ let out ← entryGet entry "out"
271
+ if ← eqv out res then pure ()
272
+ else if matched && (out == .str nullmark || isNullish out) then pure ()
273
+ else
274
+ throw (IO.userError ("Expected: " ++ (← stringify out) ++ ", got: " ++ (← stringify res)))
275
+
276
+ def handleError (entry : Value) (err : IO.Error) : SIO Unit := do
277
+ let msg := err.toString
278
+ if ← entryHas entry "err" then do
279
+ let entryErr ← entryGet entry "err"
280
+ if entryErr == .bool true || (← matchval entryErr (.str msg)) then do
281
+ if ← entryHas entry "match" then
282
+ doMatch (← entryGet entry "match")
283
+ (← omapV [("in", ← entryGet entry "in"), ("out", ← entryGet entry "res"),
284
+ ("ctx", ← entryGet entry "ctx"), ("err", .str msg)])
285
+ else
286
+ throw (IO.userError ("ERROR MATCH: [" ++ (← stringify entryErr) ++ "] <=> [" ++ msg ++ "]"))
287
+ else throw err
288
+
289
+ def runSet (group : String) (node : Value) (subject : List Value → SIO Value)
290
+ (flagNull : Bool := true) : SIO Unit := do
291
+ let fixed ← fixJson node flagNull
292
+ let testset ← listItemsOf (← getprop fixed (.str "set"))
293
+ for entry in testset do
294
+ let name ← jsString (← entryGet entry "name")
295
+ try
296
+ if !(← entryHas entry "out") && flagNull then
297
+ let _ ← setprop entry (.str "out") (.str nullmark)
298
+ let args ← resolveArgs entry
299
+ let res ← fixJson (← subject args) flagNull
300
+ let _ ← setprop entry (.str "res") res
301
+ checkResult entry args res
302
+ record group name true ""
303
+ catch e =>
304
+ try
305
+ handleError entry e
306
+ record group name true ""
307
+ catch e2 =>
308
+ record group name false e2.toString
309
+
310
+ def getpropRawPub (e : Value) (k : String) : SIO Value := entryGet e k
311
+
312
+ def runSingle (group : String) (node : Value) (actualFn : Value → SIO Value) : SIO Unit := do
313
+ try
314
+ let expected ← getpropRawPub node "out"
315
+ let actual ← actualFn (← getpropRawPub node "in")
316
+ if ← eqv expected actual then record group "single" true ""
317
+ else
318
+ record group "single" false
319
+ ("Expected: " ++ (← stringify expected) ++ ", got: " ++ (← stringify actual))
320
+ catch e => record group "single" false e.toString
321
+
322
+ -- ---------------- arg helpers ----------------
323
+
324
+ def arg1 (f : Value → SIO Value) : List Value → SIO Value :=
325
+ fun args => f (args.headD .noval)
326
+
327
+ def vget (vin : Value) (k : String) : SIO Value := do
328
+ match vin with
329
+ | .map id => pure ((omapGet (← mapEntries id) k).getD .noval)
330
+ | _ => pure .noval
331
+
332
+ def vhas (vin : Value) (k : String) : SIO Bool := do
333
+ match vin with
334
+ | .map id => pure (omapHas (← mapEntries id) k)
335
+ | _ => pure false
336
+
337
+ -- ---------------- test groups ----------------
338
+
339
+ def nullModifier : ModifyFn := fun v key parent _inj => do
340
+ if v == .str nullmark then
341
+ let _ ← setprop parent key .null
342
+ else match v with
343
+ | .str s =>
344
+ let _ ← setprop parent key (.str (s.replace nullmark "null"))
345
+ | _ => pure ()
346
+
347
+ def runWalkLog (group : String) (node : Value) : SIO Unit := do
348
+ try
349
+ let testData ← clone node
350
+ let log ← emptyList
351
+ let walklog : WalkFn := fun key v parent path => do
352
+ let ks ← if isNullish key then stringify .noval else stringify key
353
+ let vs ← stringify v
354
+ let ps ← if isNullish parent then stringify .noval else stringify parent
355
+ let ts ← pathify path
356
+ let n ← size log
357
+ let _ ← setprop log (vInt n)
358
+ (.str ("k=" ++ ks ++ ", v=" ++ vs ++ ", p=" ++ ps ++ ", t=" ++ ts))
359
+ pure v
360
+ let _ ← walk (← getpropRawPub testData "in") (after := some walklog)
361
+ let expected ← getprop (← getpropRawPub testData "out") (.str "after")
362
+ if ← eqv expected log then record group "log" true ""
363
+ else
364
+ record group "log" false
365
+ ("Expected: " ++ (← stringify expected) ++ ", got: " ++ (← stringify log))
366
+ catch e => record group "log" false e.toString
367
+
368
+ def walkCopySubject (vin : Value) : SIO Value := do
369
+ let cur ← IO.mkRef (← newList #[.noval])
370
+ let walkcopy : WalkFn := fun key v _parent path => do
371
+ if isNullish key then do
372
+ let seed ← if ismap v then emptyMap else if islist v then emptyList else pure v
373
+ cur.set (← newList #[seed])
374
+ pure v
375
+ else do
376
+ let i ← size path
377
+ let iN := i.toNat
378
+ let nv ← if isnode v then do
379
+ match (← cur.get) with
380
+ | .list r => do
381
+ let mut xs ← listItems r
382
+ while xs.size <= iN do
383
+ xs := xs.push .noval
384
+ let n ← if ismap v then emptyMap else emptyList
385
+ xs := xs.set! iN n
386
+ setListItems r xs
387
+ pure n
388
+ | _ => pure v
389
+ else pure v
390
+ let tgt ← getelem (← cur.get) (vInt (i - 1))
391
+ let _ ← setprop tgt key nv
392
+ pure v
393
+ let _ ← walk vin (before := some walkcopy)
394
+ getelem (← cur.get) (.num 0.0)
395
+
396
+ def walkDepthSubject (vin : Value) : SIO Value := do
397
+ let top ← IO.mkRef Value.noval
398
+ let curr ← IO.mkRef Value.noval
399
+ let copy : WalkFn := fun key v _parent _path => do
400
+ if isNullish key || isnode v then do
401
+ let child ← if islist v then emptyList else emptyMap
402
+ if isNullish key then do
403
+ top.set child
404
+ curr.set child
405
+ else do
406
+ let _ ← setprop (← curr.get) key child
407
+ curr.set child
408
+ else
409
+ let _ ← setprop (← curr.get) key v
410
+ pure v
411
+ let _ ← walk (← vget vin "src") (before := some copy) (maxdepth := ← vget vin "maxdepth")
412
+ top.get
413
+
414
+ def runAll (spec : Value) : SIO Unit := do
415
+ let g := getpropRawPub spec
416
+ let minor ← g "minor"
417
+ let walks ← g "walk"
418
+ let merges ← g "merge"
419
+ let getpaths ← g "getpath"
420
+ let injects ← g "inject"
421
+ let transforms ← g "transform"
422
+ let validates ← g "validate"
423
+ let selects ← g "select"
424
+ let sentinels ← g "sentinels"
425
+ let mg := getpropRawPub minor
426
+
427
+ -- minor
428
+ runSet "minor.isnode" (← mg "isnode") (arg1 (fun v => pure (.bool (isnode v))))
429
+ runSet "minor.ismap" (← mg "ismap") (arg1 (fun v => pure (.bool (ismap v))))
430
+ runSet "minor.islist" (← mg "islist") (arg1 (fun v => pure (.bool (islist v))))
431
+ runSet "minor.iskey" (← mg "iskey") (arg1 (fun v => pure (.bool (iskey v))))
432
+ (flagNull := false)
433
+ runSet "minor.strkey" (← mg "strkey") (arg1 (fun v => pure (.str (strkey v))))
434
+ (flagNull := false)
435
+ runSet "minor.isempty" (← mg "isempty") (arg1 (fun v => do pure (.bool (← isempty v))))
436
+ (flagNull := false)
437
+ runSet "minor.isfunc" (← mg "isfunc") (arg1 (fun v => pure (.bool (isfunc v))))
438
+ runSet "minor.clone" (← mg "clone") (arg1 clone) (flagNull := false)
439
+ runSet "minor.escre" (← mg "escre") (arg1 escre)
440
+ runSet "minor.escurl" (← mg "escurl") (arg1 escurl)
441
+ runSet "minor.stringify" (← mg "stringify")
442
+ (arg1 (fun vin => do
443
+ if ← vhas vin "val" then
444
+ pure (.str (← stringify (← vget vin "val") (maxlen := ← vget vin "max")))
445
+ else
446
+ pure (.str (← stringify .noval))))
447
+ (flagNull := false)
448
+ runSet "minor.jsonify" (← mg "jsonify")
449
+ (arg1 (fun vin => do
450
+ pure (.str (← jsonify (← vget vin "val") (flags := ← vget vin "flags")))))
451
+ (flagNull := false)
452
+ runSet "minor.getelem" (← mg "getelem")
453
+ (arg1 (fun vin => do
454
+ let alt ← vget vin "alt"
455
+ if isNullish alt then getelem (← vget vin "val") (← vget vin "key")
456
+ else getelem (← vget vin "val") (← vget vin "key") alt))
457
+ (flagNull := false)
458
+ runSet "minor.delprop" (← mg "delprop")
459
+ (arg1 (fun vin => do delprop (← vget vin "parent") (← vget vin "key")))
460
+ runSet "minor.size" (← mg "size") (arg1 (fun v => do pure (vInt (← size v))))
461
+ (flagNull := false)
462
+ runSet "minor.slice" (← mg "slice")
463
+ (arg1 (fun vin => do
464
+ slice (← vget vin "val") (start := ← vget vin "start") (stop := ← vget vin "end")))
465
+ (flagNull := false)
466
+ runSet "minor.pad" (← mg "pad")
467
+ (arg1 (fun vin => do
468
+ pure (.str (← pad (← vget vin "val") (padding := ← vget vin "pad")
469
+ (padchar := ← vget vin "char")))))
470
+ (flagNull := false)
471
+ runSet "minor.pathify" (← mg "pathify")
472
+ (arg1 (fun vin => do
473
+ if ← vhas vin "path" then
474
+ pure (.str (← pathify (← vget vin "path") (startin := ← vget vin "from")))
475
+ else
476
+ pure (.str (← pathify .noval (startin := ← vget vin "from") (absent := true)))))
477
+ (flagNull := false)
478
+ runSet "minor.items" (← mg "items") (arg1 items)
479
+ runSet "minor.getprop" (← mg "getprop")
480
+ (arg1 (fun vin => do
481
+ let alt ← vget vin "alt"
482
+ if isNullish alt then getprop (← vget vin "val") (← vget vin "key")
483
+ else getprop (← vget vin "val") (← vget vin "key") alt))
484
+ (flagNull := false)
485
+ runSet "minor.setprop" (← mg "setprop")
486
+ (arg1 (fun vin => do
487
+ setprop (← vget vin "parent") (← vget vin "key") (← vget vin "val")))
488
+ runSet "minor.haskey" (← mg "haskey")
489
+ (arg1 (fun vin => do
490
+ pure (.bool (← haskey (← vget vin "src") (← vget vin "key")))))
491
+ (flagNull := false)
492
+ runSet "minor.keysof" (← mg "keysof")
493
+ (arg1 (fun v => do newList ((← keysof v).map (fun s => Value.str s))))
494
+ runSet "minor.join" (← mg "join")
495
+ (arg1 (fun vin => do
496
+ let url := (← vget vin "url") == .bool true
497
+ pure (.str (← join (← vget vin "val") (sep := ← vget vin "sep") (url := url)))))
498
+ (flagNull := false)
499
+ runSet "minor.typify" (← mg "typify")
500
+ (arg1 (fun v => pure (vInt (typify v))))
501
+ (flagNull := false)
502
+ runSet "minor.setpath" (← mg "setpath")
503
+ (arg1 (fun vin => do
504
+ setpath (← vget vin "store") (← vget vin "path") (← vget vin "val")))
505
+ (flagNull := false)
506
+ runSet "minor.filter" (← mg "filter")
507
+ (arg1 (fun vin => do
508
+ let checkV ← vget vin "check"
509
+ let check : (String × Value) → Bool :=
510
+ if checkV == .str "gt3" then
511
+ fun (_, x) => match x with | .num n => n > 3.0 | _ => false
512
+ else if checkV == .str "lt3" then
513
+ fun (_, x) => match x with | .num n => n < 3.0 | _ => false
514
+ else fun _ => false
515
+ filter (← vget vin "val") check))
516
+ runSet "minor.typename" (← mg "typename")
517
+ (arg1 (fun v => do
518
+ let t : Int := match v with
519
+ | .num n => fToInt n
520
+ | _ => 0
521
+ pure (.str (typename t))))
522
+ runSet "minor.flatten" (← mg "flatten")
523
+ (arg1 (fun vin => do
524
+ match (← vget vin "depth") with
525
+ | .num n => flatten (← vget vin "val") (depth := fToInt n)
526
+ | _ => flatten (← vget vin "val")))
527
+
528
+ -- walk
529
+ runWalkLog "walk.log" (← getpropRawPub walks "log")
530
+ runSet "walk.basic" (← getpropRawPub walks "basic")
531
+ (arg1 (fun vin => do
532
+ walk vin (after := some (fun _k v _p path => do
533
+ match v with
534
+ | .str s => do
535
+ let mut parts : List String := []
536
+ for x in (← listItemsOf path) do
537
+ parts := (← jsString x) :: parts
538
+ pure (.str (s ++ "~" ++ String.intercalate "." parts.reverse))
539
+ | _ => pure v))))
540
+ runSet "walk.copy" (← getpropRawPub walks "copy") (arg1 walkCopySubject)
541
+ runSet "walk.depth" (← getpropRawPub walks "depth") (arg1 walkDepthSubject)
542
+ (flagNull := false)
543
+
544
+ -- merge
545
+ runSingle "merge.basic" (← getpropRawPub merges "basic")
546
+ (fun vin => do merge (← clone vin))
547
+ runSet "merge.cases" (← getpropRawPub merges "cases") (arg1 (fun v => merge v))
548
+ runSet "merge.array" (← getpropRawPub merges "array") (arg1 (fun v => merge v))
549
+ runSet "merge.integrity" (← getpropRawPub merges "integrity") (arg1 (fun v => merge v))
550
+ runSet "merge.depth" (← getpropRawPub merges "depth")
551
+ (arg1 (fun vin => do
552
+ merge (← vget vin "val") (maxdepth := ← vget vin "depth")))
553
+
554
+ -- getpath
555
+ runSet "getpath.basic" (← getpropRawPub getpaths "basic")
556
+ (arg1 (fun vin => do getpath (← vget vin "store") (← vget vin "path")))
557
+ runSet "getpath.relative" (← getpropRawPub getpaths "relative")
558
+ (arg1 (fun vin => do
559
+ let dpath ← match (← vget vin "dpath") with
560
+ | .str s => newList ((s.splitOn ".").map (fun x => Value.str x)).toArray
561
+ | _ => pure Value.noval
562
+ let d : InjDef := { dDparent := ← vget vin "dparent", dDpath := dpath }
563
+ getpath (← vget vin "store") (← vget vin "path") (.idef d)))
564
+ runSet "getpath.special" (← getpropRawPub getpaths "special")
565
+ (arg1 (fun vin => do
566
+ let injm ← vget vin "inj"
567
+ let d : InjDef := {
568
+ dBase := ← getprop injm (.str "base"), dMeta := ← getprop injm (.str "meta"),
569
+ dDparent := ← getprop injm (.str "dparent"), dDpath := ← getprop injm (.str "dpath"),
570
+ dKey := ← getprop injm (.str "key") }
571
+ getpath (← vget vin "store") (← vget vin "path")
572
+ (if isNullish injm then .inone else .idef d)))
573
+ runSet "getpath.handler" (← getpropRawPub getpaths "handler")
574
+ (arg1 (fun vin => do
575
+ let foo ← vFunc (fun _ _ _ _ => pure (.str "foo"))
576
+ let store ← omapV [("$TOP", ← vget vin "store"), ("$FOO", foo)]
577
+ let h ← registerFunc (fun _inj v _ref _store => do
578
+ match v with
579
+ | .func fid => callFunc fid (← getDummyInj) .noval "" .noval
580
+ | _ => pure v)
581
+ let d : InjDef := { dHandler := some h }
582
+ getpath store (← vget vin "path") (.idef d)))
583
+
584
+ -- inject
585
+ runSingle "inject.basic" (← getpropRawPub injects "basic")
586
+ (fun vin => do
587
+ inject (← clone (← getpropRawPub vin "val")) (← clone (← getpropRawPub vin "store")))
588
+ runSet "inject.string" (← getpropRawPub injects "string")
589
+ (arg1 (fun vin => do
590
+ let mid ← registerModify nullModifier
591
+ let d : InjDef := { dModify := some mid, dExtra := ← vget vin "current" }
592
+ inject (← vget vin "val") (← vget vin "store") (.idef d)))
593
+ runSet "inject.deep" (← getpropRawPub injects "deep")
594
+ (arg1 (fun vin => do inject (← vget vin "val") (← vget vin "store")))
595
+
596
+ -- transform
597
+ runSingle "transform.basic" (← getpropRawPub transforms "basic")
598
+ (fun vin => do
599
+ transform (← getpropRawPub vin "data") (← getpropRawPub vin "spec"))
600
+ for gn in ["paths", "cmds", "each", "pack", "ref"] do
601
+ runSet ("transform." ++ gn) (← getpropRawPub transforms gn)
602
+ (arg1 (fun vin => do transform (← vget vin "data") (← vget vin "spec")))
603
+ runSet "transform.modify" (← getpropRawPub transforms "modify")
604
+ (arg1 (fun vin => do
605
+ let mid ← registerModify (fun v key parent _inj => do
606
+ match v with
607
+ | .str s =>
608
+ if !(isNullish key) && !(isNullish parent) then
609
+ let _ ← setprop parent key (.str ("@" ++ s))
610
+ | _ => pure ())
611
+ let d : InjDef := { dModify := some mid, dExtra := ← vget vin "store" }
612
+ transform (← vget vin "data") (← vget vin "spec") (.idef d)))
613
+ runSet "transform.format" (← getpropRawPub transforms "format")
614
+ (arg1 (fun vin => do transform (← vget vin "data") (← vget vin "spec")))
615
+ (flagNull := false)
616
+ runSet "transform.apply" (← getpropRawPub transforms "apply")
617
+ (arg1 (fun vin => do transform (← vget vin "data") (← vget vin "spec")))
618
+
619
+ -- validate
620
+ runSet "validate.basic" (← getpropRawPub validates "basic")
621
+ (arg1 (fun vin => do validate (← vget vin "data") (← vget vin "spec")))
622
+ (flagNull := false)
623
+ for gn in ["child", "one", "exact"] do
624
+ runSet ("validate." ++ gn) (← getpropRawPub validates gn)
625
+ (arg1 (fun vin => do validate (← vget vin "data") (← vget vin "spec")))
626
+ runSet "validate.invalid" (← getpropRawPub validates "invalid")
627
+ (arg1 (fun vin => do validate (← vget vin "data") (← vget vin "spec")))
628
+ (flagNull := false)
629
+ runSet "validate.special" (← getpropRawPub validates "special")
630
+ (arg1 (fun vin => do
631
+ let injm ← vget vin "inj"
632
+ let d : InjDef := { dMeta := ← getprop injm (.str "meta") }
633
+ validate (← vget vin "data") (← vget vin "spec")
634
+ (if isNullish injm then .inone else .idef d)))
635
+
636
+ -- select
637
+ for gn in ["basic", "operators", "edge", "alts"] do
638
+ runSet ("select." ++ gn) (← getpropRawPub selects gn)
639
+ (arg1 (fun vin => do select (← vget vin "obj") (← vget vin "query")))
640
+
641
+ -- regex (parity floor: Go stdlib regexp — see design/REGEX_API.md)
642
+ let regexs ← g "regex"
643
+ runSet "regex.test" (← getpropRawPub regexs "test")
644
+ (arg1 (fun vin => do
645
+ reTest (← vget vin "pattern") (← vget vin "input")))
646
+ runSet "regex.find" (← getpropRawPub regexs "find")
647
+ (arg1 (fun vin => do
648
+ reFind (← vget vin "pattern") (← vget vin "input")))
649
+ runSet "regex.find_all" (← getpropRawPub regexs "find_all")
650
+ (arg1 (fun vin => do
651
+ reFindAll (← vget vin "pattern") (← vget vin "input")))
652
+ runSet "regex.replace" (← getpropRawPub regexs "replace")
653
+ (arg1 (fun vin => do
654
+ reReplace (← vget vin "pattern") (← vget vin "input") (← vget vin "replacement")))
655
+ runSet "regex.escape" (← getpropRawPub regexs "escape")
656
+ (arg1 (fun vin => do
657
+ reEscape (← vget vin "val")))
658
+
659
+ -- sentinels
660
+ runSet "sentinels.getprop_unify" (← getpropRawPub sentinels "getprop_unify")
661
+ (arg1 (fun vin => do
662
+ getprop (← vget vin "val") (← vget vin "key") (← vget vin "alt")))
663
+ (flagNull := false)
664
+ runSet "sentinels.getelem_absent" (← getpropRawPub sentinels "getelem_absent")
665
+ (arg1 (fun vin => do
666
+ getelem (← vget vin "val") (← vget vin "key") (← vget vin "alt")))
667
+ (flagNull := false)
668
+ runSet "sentinels.haskey_unify" (← getpropRawPub sentinels "haskey_unify")
669
+ (arg1 (fun vin => do
670
+ pure (.bool (← haskey (← vget vin "val") (← vget vin "key")))))
671
+ (flagNull := false)
672
+ runSet "sentinels.isempty_unify" (← getpropRawPub sentinels "isempty_unify")
673
+ (arg1 (fun v => do pure (.bool (← isempty v))))
674
+ (flagNull := false)
675
+ runSet "sentinels.isnode_unify" (← getpropRawPub sentinels "isnode_unify")
676
+ (arg1 (fun v => pure (.bool (isnode v))))
677
+ (flagNull := false)
678
+ runSet "sentinels.stringify_null" (← getpropRawPub sentinels "stringify_null")
679
+ (arg1 (fun vin => do pure (.str (← stringify vin))))
680
+ (flagNull := false)
681
+
682
+ -- ---------------- main ----------------
683
+
684
+ def main (argv : List String) : IO UInt32 := do
685
+ let testfile := argv.headD "../.sdk/test/test.json"
686
+ let raw ← IO.FS.readFile testfile
687
+ let ctx ← mkCtx
688
+ let go : SIO Unit := do
689
+ let alltests ← jsonRead raw
690
+ let spec ← getpropRawPub alltests "struct"
691
+ runAll spec
692
+ go.run ctx
693
+ for f in (← failures.get).reverse do
694
+ IO.println f
695
+ IO.println ""
696
+ IO.println ("PASS " ++ toString (← npass.get) ++ " FAIL " ++ toString (← nfail.get))
697
+ if (← nfail.get) > 0 then return 1 else return 0