Skip to content

Commit 9d51039

Browse files
yaml() assertions (#6459)
1 parent 56e0e22 commit 9d51039

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
* <p>
4+
* Licensed under the Moderne Source Available License (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://docs.moderne.io/licensing/moderne-source-available-license
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import {AfterRecipeText, dedentAfter, SourceSpec} from "../test";
17+
import {YamlParser} from "./parser";
18+
import {Yaml} from "./tree";
19+
20+
export function yaml(before: string | null, after?: AfterRecipeText): SourceSpec<Yaml.Documents> {
21+
return {
22+
kind: Yaml.Kind.Documents,
23+
before: before,
24+
after: dedentAfter(after),
25+
ext: 'yaml',
26+
parser: () => new YamlParser()
27+
};
28+
}

rewrite-javascript/rewrite/src/yaml/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
export * from "./assertions";
17+
export * from "./parser";
1618
export * from "./tree";
1719
export * from "./visitor";
18-
export * from "./parser";
1920

2021
import "./print";
2122
import "./rpc";

rewrite-javascript/rewrite/test/yaml/parser.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import {isDocuments, isMapping, isScalar, isSequence, Yaml, YamlParser} from "../../src/yaml";
16+
import {isDocuments, isMapping, isScalar, isSequence, Yaml, yaml, YamlParser} from "../../src/yaml";
1717
import {printer} from "../../src";
18+
import {RecipeSpec} from "../../src/test";
1819

1920
async function parseAndPrint(yaml: string): Promise<string> {
2021
const parser = new YamlParser();
@@ -323,3 +324,12 @@ block:
323324
expect(block.openingBracePrefix).toBeUndefined();
324325
});
325326
});
327+
328+
describe('yaml assertion helper', () => {
329+
const spec = new RecipeSpec();
330+
331+
test('simple mapping', () =>
332+
spec.rewriteRun(
333+
yaml('key: value')
334+
));
335+
});

0 commit comments

Comments
 (0)