Skip to content

Commit

Permalink
Merge pull request #665 from metafacture/633-oldSyntax
Browse files Browse the repository at this point in the history
Only use current fix examples for tests #633
  • Loading branch information
TobiasNx authored Feb 14, 2025
2 parents cd97ee4 + d3a0ad5 commit f180907
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 149 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Content assist is triggered with Ctrl-Space. The input above is also used in `Fi
Run workflows on the web server, passing `data`, `flux`, and `fix`:
[http://localhost:8080/xtext-service/run?data='1'{'a': '5', 'z': 10}&flux=as-lines|decode-formeta|fix|encode-formeta(style="multiline")&fix=map(a,b) map(\_else)](http://localhost:8080/xtext-service/run?data=%271%27{%27a%27:%20%275%27,%20%27z%27:%2010}&flux=as-lines|decode-formeta|fix|encode-formeta(style=%22multiline%22)&fix=map(a,c)%20map(\_else))
[http://localhost:8080/xtext-service/run?data='1'{'a': '5', 'z': 10}&flux=as-lines|decode-formeta|fix|encode-formeta(style="multiline")&fix=copy_field(a,c)](http://localhost:8080/xtext-service/run?data=%271%27{%27a%27:%20%275%27,%20%27z%27:%2010}&flux=as-lines|decode-formeta|fix|encode-formeta(style=%22multiline%22)&fix=copy_field(a,c))
## Functions and cookbook
Expand Down
26 changes: 14 additions & 12 deletions metafix/src/test/java/org/metafacture/metafix/FixParsingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public FixParsingTest() {
@Test
public void shouldParseSimple() throws Exception {
parse(
"map(a,b)"
"copy_field(a,b)"
);
}

Expand All @@ -41,7 +41,9 @@ public void shouldParseQuotedStrings() throws Exception {
"add_field(hello,\"w-o:r l/d\")",
"add_field(hello,'\tw\n\torld')",
"add_field(hello,'\\tw\\n\\torld')",
"add_field(hello,'\"world\"')"
"add_field(hello,'\"world\"')",
"add_field(\"hello\",world)",
"add_field('hello','world')"
);
}

Expand All @@ -50,17 +52,17 @@ public void shouldParseMappings() throws Exception {
parse(
"# simple field name mappings",
"",
"map(a,b)",
"copy_field(a,b)",
"",
"# nested field structure",
"",
"map(e1)",
"map(e1.e2)",
"map(e1.e2.d)",
"copy_field(e1,f1)",
"copy_field(e1.e2,f1)",
"copy_field(e1.e2.d,f1)",
"",
"# pass-through for unmapped fields",
"# pass-through for fields by default, use retain to only keep certain elements",
"",
"map(_else)",
"retain(f1, b)",
""
);
}
Expand Down Expand Up @@ -90,15 +92,15 @@ public void shouldParseTransformations() throws Exception {
"",
"# Loops",
"",
"do list(path)",
"do list(path:'test')",
"\tadd_field(foo,bar)",
LITERAL_END,
"",
"# Nested expressions",
"",
"do marc_each()",
"\tif marc_has(f700)",
"\t\tmarc_map(f700a,authors.$append)",
"do list(path:'700??','var':'$i')",
"\tif any_match('$i.4','aut')",
"\t\tcopy_field('$i.a','authors.$append')",
"\t" + LITERAL_END,
LITERAL_END,
""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public void shouldInterpretSimple() throws Exception {
@Test
public void shouldInterpretNested() throws Exception {
interpret(3,
"do marc_each()",
"\tif marc_has(f700)",
"\t\tmarc_map(f700a,authors.$append)",
"do list(path:'700??','var':'$i')",
"\tif any_equal('$i.4','aut')",
"\t\tcopy_field($i.a,authors.$append)",
"\tend",
"end",
""
Expand Down
129 changes: 0 additions & 129 deletions metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -539,135 +539,6 @@ public void doListIndexedArrayOfObjectsToArrayOfObjects() {
});
}

@Test
@MetafixToDo("implement Fix-style binds with collectors?")
public void ifInCollector() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"do entity('author')",
" map('name')",
" if all_contain('name', 'University')",
" add_field('type', 'Organization')",
" end",
"end"),
i -> {
i.startRecord("1");
i.literal("name", "A University");
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().startEntity("author");
o.get().literal("type", "Organization");
o.get().literal("name", "A University");
o.get().endEntity();
o.get().endRecord();
});
}

@Test
@MetafixToDo("implement Fix-style binds with collectors?")
public void ifInCollectorMultiRecords() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"do entity('author')",
" map('name')",
" if all_contain('name', 'University')",
" add_field('type', 'Organization')",
" end",
"end"),
i -> {
i.startRecord("1");
i.literal("name", "Max");
i.endRecord();

i.startRecord("2");
i.literal("name", "A University");
i.endRecord();

i.startRecord("3");
i.literal("name", "Mary");
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().startEntity("author");
o.get().literal("name", "Max");
o.get().endEntity();
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("author");
o.get().literal("type", "Organization");
o.get().literal("name", "A University");
o.get().endEntity();
o.get().endRecord();

o.get().startRecord("3");
o.get().startEntity("author");
o.get().literal("name", "Mary");
o.get().endEntity();
o.get().endRecord();
});
}

@Test
@MetafixToDo("implement Fix-style binds with collectors?")
public void ifInCollectorChoose() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"do choose(flushWith: 'record')",
" if all_contain('name', 'University')",
" add_field('type', 'Organization')",
" end",
"end"),
i -> {
i.startRecord("1");
i.literal("name", "Max University");
i.endRecord();

i.startRecord("2");
i.literal("name", "Max Musterman");
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().literal("type", "Organization");
o.get().endRecord();

o.get().startRecord("2");
o.get().endRecord();
});
}

@Test
@MetafixToDo("implement Fix-style binds with collectors?")
public void ifInCollectorCombine() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"do combine(name: 'fullName', value: '${first} ${last}')",
" if all_contain('author.type', 'Person')",
" map('author.first', 'first')",
" map('author.last', 'last')",
" end",
"end"),
i -> {
i.startRecord("1");
i.startEntity("author");
i.literal("type", "Organization");
i.endEntity();
i.endRecord();

i.startRecord("2");
i.startEntity("author");
i.literal("first", "Max");
i.literal("last", "Musterman");
i.literal("type", "DifferentiatedPerson");
i.endEntity();
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().endRecord();

o.get().startRecord("2");
o.get().literal("fullName", "Max Musterman");
o.get().endRecord();
});
}

private void shouldIterateOverList(final String path, final int expectedCount) {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"set_array('trace')",
Expand Down
8 changes: 4 additions & 4 deletions misc/vim/syntax/syntax-sample.fix
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ end

# Loops

do list(path)
do list(path:"base")
add_field(foo, bar) and foo.bar(key: "val=$1")
end

# Nested expressions

do marc_each()
if marc_has(f700)
marc_map(f700a, authors.$append.bla, 'bla')
do list(path:"700","var":"$i")
if any_equal("$i.4","aut")
copy_field("$i.a", "authors.$append")
end
end

Expand Down

0 comments on commit f180907

Please sign in to comment.