|
1 | | -import { deepStrictEqual, match } from "node:assert"; |
| 1 | +import { deepStrictEqual, match, rejects } from "node:assert"; |
2 | 2 | import { basename, dirname, extname, join } from "node:path"; |
3 | 3 | import { test } from "node:test"; |
4 | 4 | import metadata from "../deno.json" with { type: "json" }; |
5 | 5 | import { generateClasses, sortTopologically } from "./class.ts"; |
| 6 | +import { getDataCheck } from "./type.ts"; |
6 | 7 | import { loadSchemaFiles, type TypeSchema } from "./schema.ts"; |
7 | 8 |
|
8 | 9 | test("sortTopologically()", () => { |
@@ -80,9 +81,43 @@ test("generateClasses() imports Decimal helpers for xsd:decimal", async () => { |
80 | 81 | match(entireCode, /parseDecimal\(v\["@value"\]\)/); |
81 | 82 | }); |
82 | 83 |
|
83 | | -test("generateClasses() uses canParseDecimal() in xsd:decimal data checks", async () => { |
84 | | - const entireCode = await getDecimalUnionFixtureCode(); |
85 | | - match(entireCode, /canParseDecimal\(v\["@value"\]\)/); |
| 84 | +test("getDataCheck() uses canParseDecimal() for xsd:decimal", () => { |
| 85 | + const check = getDataCheck( |
| 86 | + "http://www.w3.org/2001/XMLSchema#decimal", |
| 87 | + {}, |
| 88 | + "v", |
| 89 | + ); |
| 90 | + match(check, /canParseDecimal\(v\["@value"\]\)/); |
| 91 | +}); |
| 92 | + |
| 93 | +test("generateClasses() rejects xsd:string and xsd:decimal unions", async () => { |
| 94 | + await rejects( |
| 95 | + Array.fromAsync(generateClasses({ |
| 96 | + "https://example.com/measure": { |
| 97 | + name: "Measure", |
| 98 | + uri: "https://example.com/measure", |
| 99 | + compactName: "Measure", |
| 100 | + entity: false, |
| 101 | + description: "A measure.", |
| 102 | + properties: [ |
| 103 | + { |
| 104 | + singularName: "amount", |
| 105 | + functional: true, |
| 106 | + compactName: "amount", |
| 107 | + uri: "https://example.com/amount", |
| 108 | + description: "An exact decimal amount.", |
| 109 | + range: [ |
| 110 | + "http://www.w3.org/2001/XMLSchema#decimal", |
| 111 | + "http://www.w3.org/2001/XMLSchema#string", |
| 112 | + ], |
| 113 | + }, |
| 114 | + ], |
| 115 | + defaultContext: |
| 116 | + "https://example.com/context" as TypeSchema["defaultContext"], |
| 117 | + }, |
| 118 | + })), |
| 119 | + /cannot have both xsd:string and xsd:decimal in its range/, |
| 120 | + ); |
86 | 121 | }); |
87 | 122 |
|
88 | 123 | if ("Deno" in globalThis) { |
@@ -142,34 +177,6 @@ async function getDecimalFixtureCode() { |
142 | 177 | return (await Array.fromAsync(generateClasses(types))).join(""); |
143 | 178 | } |
144 | 179 |
|
145 | | -async function getDecimalUnionFixtureCode() { |
146 | | - const types: Record<string, TypeSchema> = { |
147 | | - "https://example.com/measure": { |
148 | | - name: "Measure", |
149 | | - uri: "https://example.com/measure", |
150 | | - compactName: "Measure", |
151 | | - entity: false, |
152 | | - description: "A measure.", |
153 | | - properties: [ |
154 | | - { |
155 | | - singularName: "amount", |
156 | | - functional: true, |
157 | | - compactName: "amount", |
158 | | - uri: "https://example.com/amount", |
159 | | - description: "An exact decimal amount.", |
160 | | - range: [ |
161 | | - "http://www.w3.org/2001/XMLSchema#decimal", |
162 | | - "http://www.w3.org/2001/XMLSchema#string", |
163 | | - ], |
164 | | - }, |
165 | | - ], |
166 | | - defaultContext: |
167 | | - "https://example.com/context" as TypeSchema["defaultContext"], |
168 | | - }, |
169 | | - }; |
170 | | - return (await Array.fromAsync(generateClasses(types))).join(""); |
171 | | -} |
172 | | - |
173 | 180 | async function changeNodeSnapshotPath() { |
174 | 181 | const { snapshot } = await import("node:test"); |
175 | 182 | snapshot.setResolveSnapshotPath( |
|
0 commit comments