-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for duplicate type field in ELM JSON (#1403)
* Remove choice type specifier type if empty. * Make sure edit is applied to the library itself. Allow direct ELM construction in tests. * Tidy everything up * Tidy everything up
- Loading branch information
Showing
7 changed files
with
122 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/elm/IElmEdit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.cqframework.cql.cql2elm.elm; | ||
|
||
import org.hl7.elm.r1.Element; | ||
|
||
public interface IElmEdit { | ||
void edit(Element element); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/elm/ElmEditTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.cqframework.cql.cql2elm.elm; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.List; | ||
import org.hl7.elm.r1.ChoiceTypeSpecifier; | ||
import org.hl7.elm.r1.NamedTypeSpecifier; | ||
import org.hl7.elm.r1.TypeSpecifier; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ElmEditTest { | ||
|
||
@Test | ||
void removeChoiceTypeSpecifierTypeIfEmpty() { | ||
var extChoiceTypeSpecifier = new ExtChoiceTypeSpecifier(); | ||
|
||
extChoiceTypeSpecifier.setType(List.of()); | ||
ElmEdit.REMOVE_CHOICE_TYPE_SPECIFIER_TYPE_IF_EMPTY.edit(extChoiceTypeSpecifier); | ||
assertNull(extChoiceTypeSpecifier.getType()); | ||
|
||
var typeSpecifiers = List.of((TypeSpecifier) new NamedTypeSpecifier()); | ||
extChoiceTypeSpecifier.setType(typeSpecifiers); | ||
ElmEdit.REMOVE_CHOICE_TYPE_SPECIFIER_TYPE_IF_EMPTY.edit(extChoiceTypeSpecifier); | ||
assertSame(typeSpecifiers, extChoiceTypeSpecifier.getType()); | ||
} | ||
|
||
private static class ExtChoiceTypeSpecifier extends ChoiceTypeSpecifier { | ||
public List<TypeSpecifier> getType() { | ||
return type; | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/elm/ElmEditorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.cqframework.cql.cql2elm.elm; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
import org.hl7.elm.r1.ChoiceTypeSpecifier; | ||
import org.hl7.elm.r1.Library; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ElmEditorTest { | ||
private int editCount = 0; | ||
private final ElmEditor editor = new ElmEditor(List.of(element -> editCount++)); | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
editCount = 0; | ||
} | ||
|
||
@Test | ||
void edit() { | ||
editor.edit(new Library()); | ||
assertEquals(editCount, 1); | ||
} | ||
|
||
@Test | ||
void applyEdits1() { | ||
editor.applyEdits(null); | ||
assertEquals(editCount, 0); | ||
} | ||
|
||
@Test | ||
void applyEdits2() { | ||
editor.applyEdits(new ChoiceTypeSpecifier()); | ||
assertEquals(editCount, 1); | ||
} | ||
} |