aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-04-15 13:47:31 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-04-15 13:47:31 +0200
commit4c174428379af308926ec70bc5b58539a1863abf (patch)
tree0f2aeaa68b28e0c86925fd4ae0e2d893d020efdc /tests
parent8b5538ed49925aaf9fa22e961bd632bed8458184 (diff)
Implement enum synthesis from union
A union which has enumerations with a common base as members can be transformed to an equivalent enumeration.
Diffstat (limited to 'tests')
-rw-r--r--tests/dump/driver.cxx12
-rw-r--r--tests/schema/enumeration/makefile35
-rw-r--r--tests/schema/enumeration/test-000.std62
-rw-r--r--tests/schema/enumeration/test-000.xsd72
-rw-r--r--tests/schema/makefile9
5 files changed, 189 insertions, 1 deletions
diff --git a/tests/dump/driver.cxx b/tests/dump/driver.cxx
index 973a30a..2e55e97 100644
--- a/tests/dump/driver.cxx
+++ b/tests/dump/driver.cxx
@@ -7,6 +7,7 @@
#include <xsd-frontend/parser.hxx>
#include <xsd-frontend/transformations/anonymous.hxx>
+#include <xsd-frontend/transformations/enum-synthesis.hxx>
#include <xsd-frontend/semantic-graph.hxx>
#include <xsd-frontend/traversal.hxx>
@@ -571,11 +572,14 @@ main (Int argc, Char* argv[])
//
Int i (1);
Boolean anon (false);
+ Boolean enum_synth (false);
for (; i < argc; ++i)
{
if (argv[i] == NarrowString ("--anonymous"))
anon = true;
+ else if (argv[i] == NarrowString ("--enum-synthesis"))
+ enum_synth = true;
else
break;
}
@@ -607,6 +611,14 @@ main (Int argc, Char* argv[])
//
//
+ if (enum_synth)
+ {
+ Transformations::EnumSynthesis transf;
+ transf.transform (*tu, path);
+ }
+
+ //
+ //
Schema schema;
Uses uses;
diff --git a/tests/schema/enumeration/makefile b/tests/schema/enumeration/makefile
new file mode 100644
index 0000000..d958178
--- /dev/null
+++ b/tests/schema/enumeration/makefile
@@ -0,0 +1,35 @@
+# file : tests/schema/enumeration/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make
+
+tests := 000
+
+driver := $(out_root)/tests/dump/driver
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+# Convenience alias for default target.
+#
+$(out_base)/: $(driver)
+
+# Test.
+#
+test_targets := $(addprefix $(out_base)/.test-,$(tests))
+
+$(test): $(test_targets)
+$(test_targets): driver := $(driver)
+
+.PHONY: $(out_base)/.test-%
+$(out_base)/.test-%: $(driver) $(src_base)/test-%.xsd $(src_base)/test-%.std
+ $(call message,test $(out_base)/$*,$(driver) --enum-synthesis $(src_base)/test-$*.xsd | diff -u $(src_base)/test-$*.std -)
+
+# Clean.
+#
+$(clean):
+
+# Dependencies.
+#
+$(call import,$(src_root)/tests/dump/makefile)
diff --git a/tests/schema/enumeration/test-000.std b/tests/schema/enumeration/test-000.std
new file mode 100644
index 0000000..64e3065
--- /dev/null
+++ b/tests/schema/enumeration/test-000.std
@@ -0,0 +1,62 @@
+primary
+{
+ namespace test
+ {
+ complex common-base: http://www.w3.org/2001/XMLSchema#string
+ {
+ }
+ complex base: test#common-base
+ {
+ }
+ enumeration one: test#base
+ {
+ <romance documentation>
+ enumerator romance
+ enumerator fiction
+ enumerator horror
+ }
+ enumeration two: test#common-base
+ {
+ enumerator horror
+ enumerator history
+ enumerator philosophy
+ }
+ enumeration three: http://www.w3.org/2001/XMLSchema#anyURI
+ {
+ enumerator foo
+ enumerator bar
+ }
+ enumeration union0: test#common-base
+ {
+ <romance documentation>
+ enumerator romance
+ enumerator fiction
+ enumerator horror
+ enumerator history
+ enumerator philosophy
+ }
+ <union1 documentation>
+ enumeration union1: test#common-base
+ {
+ <romance documentation>
+ enumerator romance
+ enumerator fiction
+ enumerator horror
+ enumerator history
+ enumerator philosophy
+ }
+ union union2 test#one test#union1 test#common-base
+ union union3 test#one test#three
+ complex complex1
+ {
+ element a
+ [1, 1] sequence
+ {
+ [1, 1] element a test#union1
+ }
+ }
+ complex complex2: test#union1
+ {
+ }
+ }
+}
diff --git a/tests/schema/enumeration/test-000.xsd b/tests/schema/enumeration/test-000.xsd
new file mode 100644
index 0000000..08539bf
--- /dev/null
+++ b/tests/schema/enumeration/test-000.xsd
@@ -0,0 +1,72 @@
+<?xml version="1.0"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
+
+ <!-- Enumeration synthesis -->
+
+ <simpleType name="common-base">
+ <restriction base="string"/>
+ </simpleType>
+
+ <simpleType name="base">
+ <restriction base="t:common-base"/>
+ </simpleType>
+
+ <simpleType name="one">
+ <restriction base="t:base">
+ <enumeration value="romance">
+ <annotation>
+ <documentation>romance documentation</documentation>
+ </annotation>
+ </enumeration>
+ <enumeration value="fiction"/>
+ <enumeration value="horror"/>
+ </restriction>
+ </simpleType>
+
+ <simpleType name="two">
+ <restriction base="t:common-base">
+ <enumeration value="horror"/>
+ <enumeration value="history"/>
+ <enumeration value="philosophy"/>
+ </restriction>
+ </simpleType>
+
+ <simpleType name="three">
+ <restriction base="anyURI">
+ <enumeration value="foo"/>
+ <enumeration value="bar"/>
+ </restriction>
+ </simpleType>
+
+ <simpleType name="union0">
+ <union memberTypes="t:one t:two t:union1"/>
+ </simpleType>
+
+ <simpleType name="union1">
+ <annotation>
+ <documentation>union1 documentation</documentation>
+ </annotation>
+ <union memberTypes="t:one t:two"/>
+ </simpleType>
+
+ <simpleType name="union2">
+ <union memberTypes="t:one t:union1 t:common-base"/>
+ </simpleType>
+
+ <simpleType name="union3">
+ <union memberTypes="t:one t:three"/>
+ </simpleType>
+
+ <complexType name="complex1">
+ <sequence>
+ <element name="a" type="t:union1"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="complex2">
+ <simpleContent>
+ <extension base="t:union1"/>
+ </simpleContent>
+ </complexType>
+
+</schema>
diff --git a/tests/schema/makefile b/tests/schema/makefile
index b0fab92..fde5482 100644
--- a/tests/schema/makefile
+++ b/tests/schema/makefile
@@ -5,7 +5,14 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
-tests := annotation anonymous attribute-group element-group default union
+tests := \
+annotation \
+anonymous \
+attribute-group \
+default \
+element-group \
+enumeration \
+union
default := $(out_base)/
test := $(out_base)/.test