diff --git a/README.md b/README.md index ce118d85..b5d82efb 100644 --- a/README.md +++ b/README.md @@ -303,19 +303,6 @@ Options: #### Record-level functions -##### `add_array` - -Creates a new array (with optional values). - -```perl -add_array("") -add_array("", ""[, ...]) -``` - -[Example in Playground](https://metafacture.org/playground/?example=add_array) - -[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+add_array+{") - ##### `add_field` Creates a field with a defined value. @@ -328,19 +315,6 @@ add_field("", "") [Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+add_field+{") -##### `add_hash` - -Creates a new hash (with optional values). - -```perl -add_hash("") -add_hash("", "subfieldName": ""[, ...]) -``` - -[Example in Playground](https://metafacture.org/playground/?example=add_hash) - -[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+add_hash+{") - ##### `array` Converts a hash/object into an array. @@ -1053,7 +1027,7 @@ E.g.: ```perl # "ccm:university":["https://ror.org/0304hq317"] # "ccm:university_DISPLAYNAME":["Gottfried Wilhelm Leibniz Universität Hannover"] -add_array("sourceOrga[]") +set_array("sourceOrga[]") do list_as(orgId: "ccm:university[]", orgName: "ccm:university_DISPLAYNAME[]") copy_field(orgId, "sourceOrga[].$append.id") copy_field(orgName, "sourceOrga[].$last.name") diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java index 9ea85d1e..88917916 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java @@ -64,7 +64,7 @@ public void doList() { @Test public void doListExplicitAppend() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('author')", + "set_array('author')", "do list('path': 'name', 'var': 'n')", " upcase('n')", " trim('n')", @@ -212,7 +212,7 @@ public void doListPathWithDots() { @Test public void doListPathWithDotsExplicitAppend() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('author')", + "set_array('author')", "do list('path': 'some.name', 'var': 'n')", " upcase('n')", " trim('n')", @@ -237,7 +237,7 @@ public void doListPathWithDotsExplicitAppend() { @Test public void doListWithAppendAndLast() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('author[]')", + "set_array('author[]')", "do list('path': 'creator', 'var': 'c')", " copy_field('c.name', 'author[].$append.name')", " add_field('author[].$last.type', 'Default')", @@ -295,7 +295,7 @@ public void doListEntitesToLiterals() { @Test public void doListEntitesToLiteralsExplicitAppend() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('author')", + "set_array('author')", "do list('path': 'creator', 'var': 'c')", " upcase('c.name')", " trim('c.name')", @@ -322,7 +322,7 @@ public void doListEntitesToLiteralsExplicitAppend() { @Test public void doListEntitesToEntities() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('author[]')", + "set_array('author[]')", "do list('path': 'creator', 'var': 'c')", " copy_field('c.name', 'author[].$append.name')", " if all_contain('c.name', 'University')", @@ -359,7 +359,7 @@ public void doListEntitesToEntities() { @Test public void wildcardForNestedEntities() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('author[]')", + "set_array('author[]')", "do list('path': 'creator', 'var': 'c')", " if any_match('c.role.*.roleTerm.*.value','aut|cre')", " copy_field('c.name', 'author[].$append.name')", @@ -430,7 +430,7 @@ public void doListIndexedArray() { @Test public void doListIndexedArrayToArrayOfObjects() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('author[]')", + "set_array('author[]')", "do list('path': 'name[]', 'var': 'n')", " copy_field('n', 'author[].$append.name')", "end", @@ -483,7 +483,7 @@ public void doListIndexedArrayOfObjects() { @Test public void doListIndexedArrayOfObjectsExplicitAppend() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('author')", + "set_array('author')", "do list('path': 'name[]', 'var': 'n')", " copy_field('n.name', 'author.$append')", "end", @@ -510,7 +510,7 @@ public void doListIndexedArrayOfObjectsExplicitAppend() { @Test public void doListIndexedArrayOfObjectsToArrayOfObjects() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('author[]')", + "set_array('author[]')", "do list('path': 'name[]', 'var': 'n')", " copy_field('n.name', 'author[].$append.name')", "end", @@ -670,7 +670,7 @@ public void ifInCollectorCombine() { private void shouldIterateOverList(final String path, final int expectedCount) { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('trace')", + "set_array('trace')", "do list(path: '" + path + "', 'var': '$i')", " add_field('trace.$append', 'true')", "end", @@ -716,7 +716,7 @@ public void shouldIterateOverListWithWildcard() { private void shouldIterateOverListOfHashes(final String path, final int expectedCount) { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('trace')", + "set_array('trace')", "do list(path: '" + path + "', 'var': '$i')", " add_field('trace.$append', 'true')", "end", @@ -771,7 +771,7 @@ public void shouldIterateOverListOfHashesWithWildcard() { // See https://github.com/metafacture/metafacture-fix/issues/119 public void shouldPerformComplexOperationWithPathWildcard() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('coll[]')", + "set_array('coll[]')", "do list(path: 'feld?', 'var': '$i')", " add_field('coll[].$append.feldtest', 'true')", " copy_field('$i.a.value', 'coll[].$last.a')", @@ -847,7 +847,7 @@ public void shouldPerformComplexOperationWithPathWildcard() { @Test public void shouldDoListAsWithSingleList() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('sourceOrga[]')", + "set_array('sourceOrga[]')", "do list_as(orgId: 'ccm:university[]')", " copy_field(orgId, 'sourceOrga[].$append.id')", "end" @@ -881,7 +881,7 @@ public void shouldDoListAsWithSingleList() { @Test public void shouldDoListAsWithMultipleLists() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('sourceOrga[]')", + "set_array('sourceOrga[]')", "do list_as(orgId: 'ccm:university[]', orgName: 'ccm:university_DISPLAYNAME[]', orgLoc: 'ccm:university_LOCATION[]')", " copy_field(orgId, 'sourceOrga[].$append.id')", " copy_field(orgName, 'sourceOrga[].$last.name')", @@ -937,9 +937,9 @@ public void shouldDoListAsWithMultipleLists() { @Test // checkstyle-disable-line JavaNCSS public void shouldDoListAsWithMultipleListsOfDifferentSizes() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('sourceOrga[]')", + "set_array('sourceOrga[]')", "do list_as(orgId: 'ccm:university[]', orgName: 'ccm:university_DISPLAYNAME[]', orgLoc: 'ccm:university_LOCATION[]')", - " add_hash('sourceOrga[].$append')", + " set_hash('sourceOrga[].$append')", " copy_field(orgId, 'sourceOrga[].$last.id')", " copy_field(orgName, 'sourceOrga[].$last.name')", " copy_field(orgLoc, 'sourceOrga[].$last.location')", diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixIfTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixIfTest.java index 35ab30fb..5b8000dc 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixIfTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixIfTest.java @@ -1624,7 +1624,7 @@ public void shouldReportArrayEntityAsArray() { @Test public void shouldReportEmptyArrayAsArray() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array(foo)", + "set_array(foo)", "if is_array(foo)", " add_field(test,ok)", "end" @@ -1767,7 +1767,7 @@ public void shouldReportEmptyArrayEntityAsEmpty() { @Test public void shouldReportEmptyArrayAsEmpty() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array(foo)", + "set_array(foo)", "if is_empty(foo)", " add_field(test,ok)", "end" @@ -2127,7 +2127,7 @@ public void shouldReportHashAsObject() { @Test public void shouldReportEmptyHashAsObject() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_hash(foo)", + "set_hash(foo)", "if is_object(foo)", " add_field(test,ok)", "end" @@ -2499,7 +2499,7 @@ public void shouldMatchString() { @Test public void shouldTestMacroVariable() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('type')", + "set_array('type')", "do put_macro('test')", " if str_contain('name', 'a$[var]')", " add_field('type.$append', 'Organization: $[var]')", diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixLookupTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixLookupTest.java index 579b2e19..d527fb80 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixLookupTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixLookupTest.java @@ -144,7 +144,7 @@ public void inlineDotNotationNested() { @Test public void shouldLookupInternalArrayWithAsterisk() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('title', 'Aloha')", + "set_array('title', 'Aloha')", LOOKUP + " Aloha: Alohaeha)" ), i -> { @@ -162,7 +162,7 @@ public void shouldLookupInternalArrayWithAsterisk() { @Test public void shouldLookupDeduplicatedInternalArrayWithAsterisk() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('title', 'Aloha', 'Aloha')", + "set_array('title', 'Aloha', 'Aloha')", "uniq('title')", LOOKUP + " Aloha: Alohaeha)" ), @@ -182,8 +182,8 @@ public void shouldLookupDeduplicatedInternalArrayWithAsterisk() { public void shouldNotLookupCopiedInternalArrayWithAsterisk() { MetafixTestHelpers.assertExecutionException(IllegalStateException.class, "Expected Array or Hash, got String", () -> MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('data', 'Aloha')", - "add_array('title')", + "set_array('data', 'Aloha')", + "set_array('title')", "copy_field('data', 'title')", LOOKUP + " Aloha: Alohaeha)" ), @@ -200,8 +200,8 @@ public void shouldNotLookupCopiedInternalArrayWithAsterisk() { @Test public void shouldLookupCopiedInternalArrayWithAsteriskExplicitAppend() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('data', 'Aloha')", - "add_array('title')", + "set_array('data', 'Aloha')", + "set_array('title')", "copy_field('data', 'title.$append')", LOOKUP + " Aloha: Alohaeha)" ), @@ -222,9 +222,9 @@ public void shouldLookupCopiedInternalArrayWithAsteriskExplicitAppend() { public void shouldNotLookupCopiedDeduplicatedInternalArrayWithAsterisk() { MetafixTestHelpers.assertExecutionException(IllegalStateException.class, "Expected Array or Hash, got String", () -> MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('data', 'Aloha', 'Aloha')", + "set_array('data', 'Aloha', 'Aloha')", "uniq('data')", - "add_array('title')", + "set_array('title')", "copy_field('data', 'title')", LOOKUP + " Aloha: Alohaeha)" ), @@ -241,9 +241,9 @@ public void shouldNotLookupCopiedDeduplicatedInternalArrayWithAsterisk() { @Test public void shouldLookupCopiedDeduplicatedInternalArrayWithAsteriskExplicitAppend() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('data', 'Aloha', 'Aloha')", + "set_array('data', 'Aloha', 'Aloha')", "uniq('data')", - "add_array('title')", + "set_array('title')", "copy_field('data', 'title.$append')", LOOKUP + " Aloha: Alohaeha)" ), @@ -263,7 +263,7 @@ public void shouldLookupCopiedDeduplicatedInternalArrayWithAsteriskExplicitAppen @Test public void shouldLookupCopiedExternalArrayWithAsteriskExplicitAppend() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('title')", + "set_array('title')", "copy_field('data', 'title.$append')", LOOKUP + " Aloha: Alohaeha)" ), @@ -285,7 +285,7 @@ public void shouldLookupCopiedExternalArrayWithAsteriskExplicitAppend() { public void shouldLookupCopiedDeduplicatedExternalArrayWithAsteriskExplicitAppend() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "uniq('data')", - "add_array('title')", + "set_array('title')", "copy_field('data', 'title.$append')", LOOKUP + " Aloha: Alohaeha)" ), @@ -309,7 +309,7 @@ public void shouldNotLookupMovedDeduplicatedExternalArrayWithAsterisk() { MetafixTestHelpers.assertExecutionException(IllegalStateException.class, "Expected Array or Hash, got String", () -> MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "uniq('data')", - "add_array('title')", + "set_array('title')", "move_field('data', 'title')", LOOKUP + " Aloha: Alohaeha)" ), @@ -329,7 +329,7 @@ public void shouldNotLookupMovedDeduplicatedExternalArrayWithAsterisk() { public void shouldLookupMovedDeduplicatedExternalArrayWithAsteriskExplicitAppend() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "uniq('data')", - "add_array('title')", + "set_array('title')", "move_field('data', 'title.$append')", LOOKUP + " Aloha: Alohaeha)" ), @@ -351,7 +351,7 @@ public void shouldLookupMovedDeduplicatedExternalArrayWithAsteriskExplicitAppend public void shouldNotLookupMovedExternalArrayWithAsterisk() { MetafixTestHelpers.assertExecutionException(IllegalStateException.class, "Expected Array or Hash, got String", () -> MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('title')", + "set_array('title')", "move_field('data', 'title')", LOOKUP + " Aloha: Alohaeha)" ), @@ -369,7 +369,7 @@ public void shouldNotLookupMovedExternalArrayWithAsterisk() { @Test public void shouldLookupMovedExternalArrayWithAsteriskExplicitAppend() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('title')", + "set_array('title')", "move_field('data', 'title.$append')", LOOKUP + " Aloha: Alohaeha)" ), @@ -994,9 +994,9 @@ public void shouldLookupInCopiedNestedArraysCreatedWithPrepend() { private void shouldLookupInCopiedNestedArraysCreatedWith(final String reservedField) { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "put_map('rswk-indicator', s: 'SubjectHeading')", - "add_array('subject[]')", - "add_array('subject[]." + reservedField + ".componentList[]')", - "add_array('subject[].$last.componentList[]." + reservedField + ".type[]')", + "set_array('subject[]')", + "set_array('subject[]." + reservedField + ".componentList[]')", + "set_array('subject[].$last.componentList[]." + reservedField + ".type[]')", "do list(path: 'D', 'var': '$i')", " copy_field('$i', 'subject[].$last.componentList[].$last.type[]." + reservedField + "')", "end", @@ -1247,7 +1247,7 @@ public void shouldExplicitLookupRdfUrlWithRedirection() { @Test // Scenario 1 public void shouldLookupInExternalRdfMapGetObjectOfSubjectWithTargetedPredicateOfSpecificLanguage() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('prefLabel', 'https://w3id.org/kim/hochschulfaechersystematik/n4')", + "set_array('prefLabel', 'https://w3id.org/kim/hochschulfaechersystematik/n4')", "put_rdfmap('" + RDF_MAP + "', 'rdfmap', target: 'skos:prefLabel', select_language: 'de')", "lookup('prefLabel.*', 'rdfmap')" ), @@ -1266,7 +1266,7 @@ public void shouldLookupInExternalRdfMapGetObjectOfSubjectWithTargetedPredicateO @Test // Scenario 2 public void shouldLookupInExternalRdfMapGetSubjectWithTargetedPredicateOfSpecificLanguage() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('id', 'Mathematics, Natural Sciences')", + "set_array('id', 'Mathematics, Natural Sciences')", "put_rdfmap('" + RDF_MAP + "', 'rdfmap', target: 'skos:prefLabel', select_language: 'en')", "lookup('id.*', 'rdfmap')" ), @@ -1408,7 +1408,7 @@ public void shouldLookupRdfDefinedPropertyToSubject() { private void shouldLookupInExternalRdfMapGetObjectWithTargetedPredicateOfSpecificLanguage(final String target) { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('prefLabel', 'Mathematics, Natural Sciences')", + "set_array('prefLabel', 'Mathematics, Natural Sciences')", "put_rdfmap('" + RDF_MAP + "', 'rdfmap', target: '" + target + "', select_language: 'de')", "lookup('prefLabel.*', 'rdfmap')" ), diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java index a430aef6..8b167257 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java @@ -2153,7 +2153,7 @@ public void replaceAllInOptionalSubfieldInArrayOfObjectsWithAsterisk() { @Test public void inDoBindCopyFieldWithVarInSourceAndTarget() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('RSWK[]')", + "set_array('RSWK[]')", "do list(path: '650??', 'var': '$i')", " copy_field('$i.a', 'RSWK[].$append.subjectTopicName')", " copy_field('$i.v', 'RSWK[].$last.subjectGenre')", @@ -2191,7 +2191,7 @@ public void inDoBindCopyFieldWithVarInSourceAndTarget() { @Test public void replaceAllWithWildcardAfterCopyFieldWithVarInSourceAndTarget() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('RSWK[]')", + "set_array('RSWK[]')", "do list(path: '650??', 'var': '$i')", " copy_field('$i.a', 'RSWK[].$append.subjectTopicName')", " copy_field('$i.v', 'RSWK[].$last.subjectGenre')", @@ -2230,7 +2230,7 @@ public void replaceAllWithWildcardAfterCopyFieldWithVarInSourceAndTarget() { @Test public void multipleReplaceAllWithWildcardAfterCopyFieldWithVarInSourceAndTarget() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('RSWK[]')", + "set_array('RSWK[]')", "do list(path: '650??', 'var': '$i')", " copy_field('$i.a', 'RSWK[].$append.subjectTopicName')", " copy_field('$i.v', 'RSWK[].$last.subjectGenre')", @@ -2271,7 +2271,7 @@ public void multipleReplaceAllWithWildcardAfterCopyFieldWithVarInSourceAndTarget public void copyFieldToSubfieldOfArrayOfObjectsWithIndexImplicitAppend() { MetafixTestHelpers.assertProcessException(IllegalArgumentException.class, "Can't find: 1 in: null", () -> MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('test[]')", + "set_array('test[]')", "copy_field('key', 'test[].1.field')" ), i -> { @@ -2288,7 +2288,7 @@ public void copyFieldToSubfieldOfArrayOfObjectsWithIndexImplicitAppend() { @Test public void copyFieldToSubfieldOfArrayOfObjectsWithExplicitAppend() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('test[]')", + "set_array('test[]')", "copy_field('key', 'test[].$append.field')" ), i -> { @@ -2312,7 +2312,7 @@ public void copyFieldToSubfieldOfArrayOfObjectsWithExplicitAppend() { public void copyFieldToSubfieldOfArrayOfStringsWithIndexImplicitAppend() { MetafixTestHelpers.assertProcessException(IndexOutOfBoundsException.class, "Index 0 out of bounds for length 0", () -> MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('test[]')", + "set_array('test[]')", "copy_field('key', 'test[].1')" ), i -> { @@ -2329,7 +2329,7 @@ public void copyFieldToSubfieldOfArrayOfStringsWithIndexImplicitAppend() { @Test public void copyFieldToSubfieldOfArrayOfStringsWithExplicitAppend() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('test[]')", + "set_array('test[]')", "copy_field('key', 'test[].$append')" ), i -> { @@ -2442,7 +2442,7 @@ public void addFieldIntoArrayOfObjectsWithLastWildcardLastEmpty() { @Test public void shouldReplaceAllRegexesInCopiedArraySubField() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('coll[]')", + "set_array('coll[]')", "copy_field('a', 'coll[].$append.a')", "replace_all('coll[].*.a', 'o', '__')" ), @@ -2466,7 +2466,7 @@ public void shouldReplaceAllRegexesInCopiedArraySubField() { @Test public void shouldReplaceAllRegexesInMovedArraySubField() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('coll[]')", + "set_array('coll[]')", "move_field('a', 'coll[].$append.a')", "replace_all('coll[].*.a', 'o', '__')" ), @@ -2489,7 +2489,7 @@ public void shouldReplaceAllRegexesInMovedArraySubField() { @Test public void shouldReplaceAllRegexesInCopiedArraySubFieldOriginal() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('coll[]')", + "set_array('coll[]')", "copy_field('a', 'coll[].$append.a')", "replace_all('a', 'o', '__')" ), @@ -2513,7 +2513,7 @@ public void shouldReplaceAllRegexesInCopiedArraySubFieldOriginal() { @Test public void shouldReplaceAllRegexesInListCopiedArraySubField() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('coll[]')", + "set_array('coll[]')", "do list(path: 'a', 'var': '$i')", " copy_field('$i', 'coll[].$append.a')", "end", @@ -2539,7 +2539,7 @@ public void shouldReplaceAllRegexesInListCopiedArraySubField() { @Test public void shouldCopyBindVarWithDollarAfterLookup() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('@coll[]')", + "set_array('@coll[]')", "do list(path: 'a', 'var': '$i')", " lookup('$i.name')", " copy_field('$i.name', '@coll[].$append')", @@ -2566,7 +2566,7 @@ public void shouldCopyBindVarWithDollarAfterLookup() { @Test public void shouldCopyToFieldWithIndexAndReservedFieldName() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('a[].*.test[]', 'test')", + "set_array('a[].*.test[]', 'test')", "copy_field('some', 'a[].1.test[].$append')", "remove_field('some')" ), @@ -2605,7 +2605,7 @@ public void shouldCopyToFieldWithIndexAndReservedFieldName() { @Test public void shouldCopyToFieldWithTwoReservedFieldNames() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('a[].*.test[]', 'test')", + "set_array('a[].*.test[]', 'test')", "copy_field('some', 'a[].$first.test[].$append')", "remove_field('some')" ), @@ -2807,11 +2807,11 @@ public void addFieldWithReplaceAllArray() { private void addFieldWithReplaceAllArray(final boolean replaceAll) { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "do list(path: 'contribution[]', 'var': '$i')", - " add_array('$i.agent.altLabel[]')", + " set_array('$i.agent.altLabel[]')", " add_field('$i.agent.altLabel[].$append', 'contribution')", "end", "do list(path: 'subject[]', 'var': '$i')", - " add_array('$i.altLabel[]')", + " set_array('$i.altLabel[]')", " add_field('$i.altLabel[].$append', 'subject')", "end", replaceAll ? "replace_all('contribution[].*.agent.altLabel[].*', 't', '')" : "", @@ -2864,10 +2864,10 @@ public void setArrayWithReplaceAll() { private void setArrayWithReplaceAll(final boolean replaceAll) { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "do list(path: 'contribution[]', 'var': '$i')", - " add_array('$i.agent.altLabel[]', 'contribution')", + " set_array('$i.agent.altLabel[]', 'contribution')", "end", "do list(path: 'subject[]', 'var': '$i')", - " add_array('$i.altLabel[]', 'subject')", + " set_array('$i.altLabel[]', 'subject')", "end", replaceAll ? "replace_all('contribution[].*.agent.altLabel[].*', 't', '')" : "", replaceAll ? "replace_all('subject[].*.altLabel[].*', 't', '')" : "" @@ -2919,11 +2919,11 @@ public void copyFieldWithReplaceAllArray() { private void copyFieldWithReplaceAllArray(final boolean replaceAll) { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "do list(path: 'contribution[]', 'var': '$i')", - " add_array('$i.agent.altLabel[]')", + " set_array('$i.agent.altLabel[]')", " copy_field('$i.label', '$i.agent.altLabel[].$append')", "end", "do list(path: 'subject[]', 'var': '$i')", - " add_array('$i.altLabel[]')", + " set_array('$i.altLabel[]')", " copy_field('$i.label', '$i.altLabel[].$append')", "end", replaceAll ? "replace_all('contribution[].*.agent.altLabel[].*', 't', '')" : "", @@ -2976,11 +2976,11 @@ public void pasteWithReplaceAll() { private void pasteWithReplaceAll(final boolean replaceAll) { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "do list(path: 'contribution[]', 'var': '$i')", - " add_array('$i.agent.altLabel[]')", + " set_array('$i.agent.altLabel[]')", " paste('$i.agent.altLabel[].$append', '$i.label', '~!')", "end", "do list(path: 'subject[]', 'var': '$i')", - " add_array('$i.altLabel[]')", + " set_array('$i.altLabel[]')", " paste('$i.altLabel[].$append', '$i.label', '~!')", "end", replaceAll ? "replace_all('contribution[].*.agent.altLabel[].*', ' !', '')" : "", diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java index 0d17e6d1..b8c13b87 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java @@ -261,7 +261,7 @@ public void add() { @Test public void addWithAppendInNewArray() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('my.name')", + "set_array('my.name')", "add_field('my.name.$append','patrick')", "add_field('my.name.$append','nicolas')" ), @@ -634,7 +634,7 @@ public void complexAppendWithArrayOfObjects() { @Test public void appendWithWildcard() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('stringimals[]')", + "set_array('stringimals[]')", "copy_field('?nimal', 'stringimals[].$append')" ), i -> { @@ -697,7 +697,7 @@ public void simpleCopyWithWildcard() { @Test public void appendWithMultipleWildcards() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('stringimals[]')", + "set_array('stringimals[]')", "copy_field('?ni??l', 'stringimals[].$append')" ), i -> { @@ -728,7 +728,7 @@ public void appendWithMultipleWildcards() { @Test public void appendWithAsteriksWildcard() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('stringimals[]')", + "set_array('stringimals[]')", "copy_field('*al', 'stringimals[].$append')" ), i -> { @@ -758,7 +758,7 @@ public void appendWithAsteriksWildcard() { @Test public void appendWithBracketWildcard() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('stringimals[]')", + "set_array('stringimals[]')", "copy_field('[ac]nimal', 'stringimals[].$append')" ), i -> { @@ -788,7 +788,7 @@ public void appendWithBracketWildcard() { // See https://github.com/metafacture/metafacture-fix/issues/89 public void appendWithAsteriksWildcardAtTheEnd() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('stringimals[]')", + "set_array('stringimals[]')", "copy_field('ani*', 'stringimals[].$append')" ), i -> { @@ -833,7 +833,7 @@ public void appendWithAsteriksWildcardAtTheEnd() { @MetafixToDo("See https://github.com/metafacture/metafacture-fix/pull/113") public void shouldCopyArrayFieldWithoutAsterisk() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('TEST_TWO[]')", + "set_array('TEST_TWO[]')", "copy_field('test[]', 'TEST_TWO[].$append')" ), i -> { @@ -894,7 +894,7 @@ public void copyFieldArrayOfObjectsAndListNewArrayOfObjectsAndMoveSubfield() { // See https://github.com/metafacture/metafacture-fix/issues/121 public void shouldCopyArrayFieldWithAsterisk() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('TEST_TWO[]')", + "set_array('TEST_TWO[]')", "copy_field('test[].*', 'TEST_TWO[].$append')" ), i -> { @@ -927,7 +927,7 @@ public void shouldCopyArrayFieldWithAsterisk() { // See https://github.com/metafacture/metafacture-fix/issues/121 public void shouldCopyNestedArrayFieldWithAsterisk() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('TEST_4[]')", + "set_array('TEST_4[]')", "copy_field('nestedTest[].*.test[].*', 'TEST_4[].$append')" ), i -> { @@ -982,7 +982,7 @@ public void shouldCopyNestedArrayFieldWithAsterisk() { // See https://github.com/metafacture/metafacture-fix/issues/121 public void shouldCopyArraySubFieldWithAsterisk() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('TEST_5[]')", + "set_array('TEST_5[]')", "copy_field('coll[].*.b', 'TEST_5[].$append')" ), i -> { @@ -1402,7 +1402,7 @@ public void copy() { @Test public void copyIntoArrayOfStrings() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - // "add_array('author')", <- results in separate objects/entities here + // "set_array('author')", <- results in separate objects/entities here "copy_field('your.name','author.name[]')", "remove_field('your')"), i -> { @@ -1582,7 +1582,7 @@ public void copyIntoImplicitArrayPrepend() { @Test public void copyIntoExplicitArrayAppend() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('author[]')", + "set_array('author[]')", "copy_field('your.name','author[].$append.name')", "remove_field('your')"), i -> { @@ -1610,7 +1610,7 @@ public void copyIntoExplicitArrayAppend() { @Test public void copyIntoArrayTopLevel() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('author[]')", + "set_array('author[]')", "copy_field('your.name', 'author[]')", "remove_field('your')"), i -> { @@ -1854,7 +1854,7 @@ public void removeArrayElementsByWildcard() { @Test public void setArray() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('foo[]','a','b','c')"), + "set_array('foo[]','a','b','c')"), i -> { i.startRecord("1"); i.endRecord(); @@ -1873,7 +1873,7 @@ public void setArray() { // See https://github.com/metafacture/metafacture-fix/issues/111 public void setArrayReplaceExisting() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('foo[]','a','b','c')"), + "set_array('foo[]','a','b','c')"), i -> { i.startRecord("1"); i.startEntity("foo[]"); @@ -1897,7 +1897,7 @@ public void setArrayReplaceExisting() { // See https://github.com/metafacture/metafacture-fix/issues/130 public void setArrayInArrayWithAsterisk() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('foo[].*.test[]', 'test')"), + "set_array('foo[].*.test[]', 'test')"), i -> { i.startRecord("1"); i.startEntity("foo[]"); @@ -1929,7 +1929,7 @@ public void setArrayInArrayWithAsterisk() { @Test public void setHash() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_hash('foo','a': 'b','c': 'd')"), + "set_hash('foo','a': 'b','c': 'd')"), i -> { i.startRecord("1"); i.endRecord(); @@ -1947,7 +1947,7 @@ public void setHash() { // See https://github.com/metafacture/metafacture-fix/issues/111 public void setHashReplaceExisting() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_hash('foo','a': 'b','c': 'd')"), + "set_hash('foo','a': 'b','c': 'd')"), i -> { i.startRecord("1"); i.startEntity("foo"); @@ -2131,7 +2131,7 @@ public void shouldPrintRecordToFile() throws IOException { @Test public void hashFromArray() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('foo','a','b','c','d')", + "set_array('foo','a','b','c','d')", "hash('foo')"), i -> { i.startRecord("1"); @@ -2149,7 +2149,7 @@ public void hashFromArray() { @Test public void arrayFromHash() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_hash('foo','a': 'b','c': 'd')", + "set_hash('foo','a': 'b','c': 'd')", "array('foo')"), i -> { i.startRecord("1"); @@ -2167,7 +2167,7 @@ public void arrayFromHash() { @Test public void shouldCallMacro() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('test')", + "set_array('test')", "do put_macro('test')", " add_field('test.$append', '42')", "end", @@ -2206,7 +2206,7 @@ public void shouldNotCallUnknownMacro() { @Test public void shouldCallMacroWithVariables() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('test')", + "set_array('test')", "put_vars(a: '1', b: '2')", // global variables "do put_macro('test', b: '22', c: '33')", // "static" local variables " add_field('test.$append', '$[a]-$[b]-$[c]-$[d]')", @@ -2412,11 +2412,11 @@ public void reject() { } @Test - @MetafixToDo("Is add_array with $append something we need/want? WDCD?") + @MetafixToDo("Is set_array with $append something we need/want? WDCD?") public void appendArray() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('nums[]', '1')", - "add_array('nums[].$append', '2', '3')"), + "set_array('nums[]', '1')", + "set_array('nums[].$append', '2', '3')"), i -> { i.startRecord("1"); i.endRecord(); @@ -2434,8 +2434,8 @@ public void appendArray() { @Test public void mixedArray() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('@context[]', 'https://w3id.org/kim/lrmi-profile/draft/context.jsonld')", - "add_hash('@context[].$append', '@language': 'de')"), + "set_array('@context[]', 'https://w3id.org/kim/lrmi-profile/draft/context.jsonld')", + "set_hash('@context[].$append', '@language': 'de')"), i -> { i.startRecord("1"); i.endRecord(); @@ -3384,7 +3384,7 @@ public void shouldAddRandomNumberToMarkedArray() { @Test public void shouldAddObjectWithRandomNumberToMarkedArray() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('bnimals[]')", + "set_array('bnimals[]')", "random('bnimals[].$append.number', '100')" ), i -> { diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixScriptTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixScriptTest.java index 57c11016..2141ed05 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixScriptTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixScriptTest.java @@ -228,7 +228,7 @@ public void shouldDoNothing() { @Test public void shouldIncludeFixFile() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('trace')", + "set_array('trace')", "add_field('trace.$append', 'before include')", "include('src/test/resources/org/metafacture/metafix/fixes/base.fix')", "add_field('trace.$append', 'after include')" @@ -307,7 +307,7 @@ public void shouldNotLeakVariablesFromIncludingFixFile() { @Test public void shouldIncludeFixFileInBind() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_array('trace')", + "set_array('trace')", "add_field('trace.$append', 'before bind')", "do list(path: 'data', 'var': '$i')", " paste('trace.$append', '~before include', '$i')", diff --git a/metafix/src/test/resources/org/metafacture/metafix/fixes/include.fix b/metafix/src/test/resources/org/metafacture/metafix/fixes/include.fix index 8bf6cb2a..9f8f6d39 100644 --- a/metafix/src/test/resources/org/metafacture/metafix/fixes/include.fix +++ b/metafix/src/test/resources/org/metafacture/metafix/fixes/include.fix @@ -1,5 +1,5 @@ unless exists("trace") - add_array("trace") + set_array("trace") end add_field("trace.$append", "before include") include("./base.fix") diff --git a/metafix/src/test/resources/org/metafacture/metafix/fixes/nested.fix b/metafix/src/test/resources/org/metafacture/metafix/fixes/nested.fix index 6ffe9317..33c9ede0 100644 --- a/metafix/src/test/resources/org/metafacture/metafix/fixes/nested.fix +++ b/metafix/src/test/resources/org/metafacture/metafix/fixes/nested.fix @@ -1,4 +1,4 @@ -add_array("trace") +set_array("trace") add_field("trace.$append", "before nested") include("src/test/resources/org/metafacture/metafix/fixes/include.fix") add_field("trace.$append", "after nested")