diff --git a/com.galenframework.specs.parent/com.galenframework.specs.tests/src/com/galenframework/tests/components/LayoutTest.xtend b/com.galenframework.specs.parent/com.galenframework.specs.tests/src/com/galenframework/tests/components/LayoutTest.xtend index e3ccbfb..5fa531b 100644 --- a/com.galenframework.specs.parent/com.galenframework.specs.tests/src/com/galenframework/tests/components/LayoutTest.xtend +++ b/com.galenframework.specs.parent/com.galenframework.specs.tests/src/com/galenframework/tests/components/LayoutTest.xtend @@ -12,10 +12,10 @@ import org.eclipse.xtext.junit4.util.ParseHelper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import com.galenframework.specs.SimpleSpecsReference -import com.galenframework.specs.ComplexSpecsReference import com.galenframework.specs.LayoutRule import com.galenframework.specs.TaggedRule +import com.galenframework.specs.VisibilityRule +import com.galenframework.specs.AlignmentRule @RunWith(XtextRunner) @InjectWith(SpecsInjectorProvider) @@ -35,18 +35,18 @@ class LayoutTest { visible ''') Assert.assertNotNull(result) - Assert.assertNotNull(result.layoutCheckSection) - val layoutSections = result.layoutCheckSection + Assert.assertNotNull(result.layoutChecks) + val layoutSections = result.layoutChecks Assert.assertEquals(1, layoutSections.size) val layoutSection = layoutSections.get(0) Assert.assertEquals("= Main =", layoutSection.name) - Assert.assertEquals(1, layoutSection.sectonRules.rules.size) + Assert.assertEquals(1, layoutSection.generalRules.size) - Assert.assertTrue(layoutSection.sectonRules.rules.get(0) instanceof LayoutRule) - val layoutRule = layoutSection.sectonRules.rules.get(0) as LayoutRule + Assert.assertTrue(layoutSection.generalRules.get(0) instanceof LayoutRule) + val layoutRule = layoutSection.generalRules.get(0) as LayoutRule Assert.assertEquals(1, layoutRule.references.size) val layoutRuleSpec = layoutRule.references.get(0) - Assert.assertTrue(layoutRuleSpec instanceof SimpleSpecsReference) + Assert.assertTrue(layoutRuleSpec.rule instanceof VisibilityRule) } @Test @@ -60,17 +60,17 @@ class LayoutTest { absent ''') Assert.assertNotNull(result) - Assert.assertNotNull(result.layoutCheckSection) - val layoutSections = result.layoutCheckSection + Assert.assertNotNull(result.layoutChecks) + val layoutSections = result.layoutChecks Assert.assertEquals(1, layoutSections.size) val layoutSection = layoutSections.get(0) Assert.assertEquals("= Main section =", layoutSection.name) - Assert.assertEquals(1, layoutSection.sectonRules.rules.size) - Assert.assertTrue(layoutSection.sectonRules.rules.get(0) instanceof LayoutRule) - val layoutRule = layoutSection.sectonRules.rules.get(0) as LayoutRule - Assert.assertTrue(layoutRule.references.get(0) instanceof SimpleSpecsReference) - val simpleSpec = layoutRule.references.get(0) as SimpleSpecsReference - Assert.assertEquals("absent", simpleSpec.value) + Assert.assertEquals(1, layoutSection.generalRules.size) + Assert.assertTrue(layoutSection.generalRules.get(0) instanceof LayoutRule) + val layoutRule = layoutSection.generalRules.get(0) as LayoutRule + Assert.assertTrue(layoutRule.references.get(0).rule instanceof VisibilityRule) + val simpleSpec = layoutRule.references.get(0).rule as VisibilityRule + Assert.assertEquals("absent", simpleSpec.name) } @Test @@ -88,24 +88,24 @@ class LayoutTest { aligned horizontally top header ''') Assert.assertNotNull(result) - Assert.assertNotNull(result.layoutCheckSection) - val layoutSections = result.layoutCheckSection + Assert.assertNotNull(result.layoutChecks) + val layoutSections = result.layoutChecks Assert.assertEquals(1, layoutSections.size) val layoutSection = layoutSections.get(0) Assert.assertEquals("= Main section =", layoutSection.name) - Assert.assertEquals(2, layoutSection.sectonRules.rules.size) - val layoutRuleLogo1 = layoutSection.sectonRules.rules.get(0) as LayoutRule - val layoutRuleLogo2 = layoutSection.sectonRules.rules.get(1) as LayoutRule + Assert.assertEquals(2, layoutSection.generalRules.size) + val layoutRuleLogo1 = layoutSection.generalRules.get(0) as LayoutRule + val layoutRuleLogo2 = layoutSection.generalRules.get(1) as LayoutRule Assert.assertEquals(2, layoutRuleLogo1.references.size) Assert.assertEquals(1, layoutRuleLogo2.references.size) val layoutRuleLogo1Visible = layoutRuleLogo1.references.get(0) - Assert.assertTrue(layoutRuleLogo1Visible instanceof SimpleSpecsReference) - Assert.assertEquals("visible", (layoutRuleLogo1Visible as SimpleSpecsReference).value) + Assert.assertTrue(layoutRuleLogo1Visible .rule instanceof VisibilityRule) + Assert.assertEquals("visible", (layoutRuleLogo1Visible.rule as VisibilityRule).name) val layoutRuleLogo1Align = layoutRuleLogo1.references.get(1) - Assert.assertTrue(layoutRuleLogo1Align instanceof ComplexSpecsReference) + Assert.assertTrue(layoutRuleLogo1Align.rule instanceof AlignmentRule) val layoutRuleLogo2Align = layoutRuleLogo2.references.get(0) - Assert.assertTrue(layoutRuleLogo2Align instanceof ComplexSpecsReference) + Assert.assertTrue(layoutRuleLogo2Align.rule instanceof AlignmentRule) } @Test @@ -120,21 +120,21 @@ class LayoutTest { aligned horizontally top header ''') Assert.assertNotNull(result) - Assert.assertNotNull(result.layoutCheckSection) - val layoutSections = result.layoutCheckSection + Assert.assertNotNull(result.layoutChecks) + val layoutSections = result.layoutChecks Assert.assertEquals(1, layoutSections.size) val layoutSection = layoutSections.get(0) Assert.assertEquals("= Main section =", layoutSection.name) - Assert.assertEquals(1, layoutSection.sectonRules.rules.size) - val layoutRule = layoutSection.sectonRules.rules.get(0) as LayoutRule + Assert.assertEquals(1, layoutSection.generalRules.size) + val layoutRule = layoutSection.generalRules.get(0) as LayoutRule Assert.assertEquals(2, layoutRule.references.size) val layoutRuleSpec1 = layoutRule.references.get(0) val layoutRuleSpec2 = layoutRule.references.get(1) - Assert.assertTrue(layoutRuleSpec1 instanceof SimpleSpecsReference) - Assert.assertTrue(layoutRuleSpec2 instanceof ComplexSpecsReference) - val simpleSpec = layoutRuleSpec1 as SimpleSpecsReference - Assert.assertEquals("visible", simpleSpec.value) + Assert.assertTrue(layoutRuleSpec1.rule instanceof VisibilityRule) + Assert.assertTrue(layoutRuleSpec2.rule instanceof AlignmentRule) + val simpleSpec = layoutRuleSpec1.rule as VisibilityRule + Assert.assertEquals("visible", simpleSpec.name) } @Test @@ -149,14 +149,14 @@ class LayoutTest { absent ''') Assert.assertNotNull(result) - Assert.assertNotNull(result.layoutCheckSection) - val layoutSections = result.layoutCheckSection + Assert.assertNotNull(result.layoutChecks) + val layoutSections = result.layoutChecks Assert.assertEquals(1, layoutSections.size) val layoutSection = layoutSections.get(0) - Assert.assertEquals(1, layoutSection.sectonRules.rules.size) + Assert.assertEquals(1, layoutSection.taggedRules.size) - Assert.assertNotNull(layoutSection.sectonRules.rules.get(0)) - val taggedRule = layoutSection.sectonRules.rules.get(0) as TaggedRule + Assert.assertNotNull(layoutSection.taggedRules.get(0)) + val taggedRule = layoutSection.taggedRules.get(0) as TaggedRule Assert.assertEquals("Tags", "@on mobile", taggedRule.name) } @@ -175,12 +175,12 @@ class LayoutTest { absent ''') Assert.assertNotNull(result) - Assert.assertNotNull(result.layoutCheckSection) - val layoutSections = result.layoutCheckSection + Assert.assertNotNull(result.layoutChecks) + val layoutSections = result.layoutChecks Assert.assertEquals(1, layoutSections.size) val layoutSection = layoutSections.get(0) - Assert.assertNotNull(layoutSection.sectonRules.rules) - Assert.assertNotNull(layoutSection.sectonRules.rules.get(0)) + Assert.assertNotNull(layoutSection.generalRules) + Assert.assertNotNull(layoutSection.generalRules.get(0)) Assert.assertEquals("= Main section =", layoutSection.name) /* * Assert.assertEquals(2,layoutSection.taggedSections.size) diff --git a/com.galenframework.specs.parent/com.galenframework.specs.tests/src/com/galenframework/tests/integrated/SpecsParsingTest.xtend b/com.galenframework.specs.parent/com.galenframework.specs.tests/src/com/galenframework/tests/integrated/SpecsParsingTest.xtend index 81a5ea4..629bd2a 100644 --- a/com.galenframework.specs.parent/com.galenframework.specs.tests/src/com/galenframework/tests/integrated/SpecsParsingTest.xtend +++ b/com.galenframework.specs.parent/com.galenframework.specs.tests/src/com/galenframework/tests/integrated/SpecsParsingTest.xtend @@ -11,8 +11,8 @@ import org.eclipse.xtext.junit4.util.ParseHelper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith - import com.galenframework.tests.SpecsInjectorProvider +import com.galenframework.specs.VisibilityRule import com.galenframework.specs.LayoutRule @RunWith(XtextRunner) @@ -42,14 +42,14 @@ class SpecsParsingTest{ Assert.assertNotNull(result.importSection) val elements = result.objects.elements val imports = result.importSection - val layoutSections = result.layoutCheckSection + val layoutSections = result.layoutChecks Assert.assertEquals(1,elements.size) Assert.assertEquals(2,imports.size) Assert.assertEquals("abc.gspec",imports.get(0).fileName) Assert.assertEquals("other.gspec",imports.get(1).fileName) Assert.assertEquals(1,layoutSections.size) val mainSection = layoutSections.get(0) - Assert.assertEquals(1,mainSection.sectonRules.rules.size) + Assert.assertEquals(1,mainSection.generalRules.size) } @@ -68,12 +68,12 @@ class SpecsParsingTest{ Assert.assertNotNull(result.objects.elements) val elementRef = result.objects.elements.get(0) Assert.assertEquals("navbar",elementRef.name) - Assert.assertNotNull(result.layoutCheckSection) - val layoutSections = result.layoutCheckSection + Assert.assertNotNull(result.layoutChecks) + val layoutSections = result.layoutChecks Assert.assertEquals(1,layoutSections.size) val mainSection = layoutSections.get(0) - Assert.assertEquals(1,mainSection.sectonRules.rules.size) - val mainSectionElementRef = mainSection.sectonRules.rules.get(0) as LayoutRule + Assert.assertEquals(1,mainSection.generalRules.size) + val mainSectionElementRef = mainSection.generalRules.get(0) as LayoutRule Assert.assertEquals("navbar",mainSectionElementRef.ref.name) /* val objects = result.objects.elements diff --git a/com.galenframework.specs.parent/com.galenframework.specs/src/com/galenframework/Specs.xtext b/com.galenframework.specs.parent/com.galenframework.specs/src/com/galenframework/Specs.xtext index a44bcbd..4d554ae 100644 --- a/com.galenframework.specs.parent/com.galenframework.specs/src/com/galenframework/Specs.xtext +++ b/com.galenframework.specs.parent/com.galenframework.specs/src/com/galenframework/Specs.xtext @@ -7,33 +7,28 @@ Model: {Model} objects=Objects? importSection+=Import* - layoutCheckSection+=Section*; + layoutChecks+=LayoutCheck*; Objects: - '@objects' + name='@objects' BEGIN (elements+=Element)+ END; Import: - '@import' fileName=ID - ; + name='@import' fileName=ID; -Section: +LayoutCheck: name=SECTION_LABEL BEGIN - sectonRules=SectonRules + (generalRules+=LayoutRule)* + (taggedRules+=TaggedRule)* END; -SectonRules: - {SectonRules} - rules+=(TaggedRule | LayoutRule)+; - LayoutRule: - (ref=[Element] ':' + ((ref=[Element] ':') BEGIN (references+=SpecsReference)+ - (sections+=Section)* END); TaggedRule: @@ -43,17 +38,27 @@ TaggedRule: END; SpecsReference: - (SimpleSpecsReference | ComplexSpecsReference); + {SpecsReference} rule=Rule; + +Rule: + (VisibilityRule | PlacementRule | AlignmentRule | SizeRule); + +VisibilityRule: + {VisibilityRule} name=('visible' | 'absent'); + +PlacementRule: + {PlacementRule} name=('near' | 'below' | 'above') INT 'to' INT 'px'; + +SizeRule: + {SizeRule} ((name='height' ('<' | '>') (INT 'px' | 'screen/height')) | + (name='width' ('<' | '>') (INT 'px' | 'screen/width@'))); -SimpleSpecsReference: - value=('visible' | 'absent'); +AlignmentRule: + name='aligned' type=AlignmentType + ref=[Element] (INT 'px')?; -ComplexSpecsReference: - {ComplexSpecsReference} ((('near' | 'below' | 'above') INT 'to' INT 'px') | - ('aligned horizontally' ('all' | 'top' | 'bottom' | 'centered') (ref=[Element])? (INT 'px')?) | - ('aligned vertically' ('all' | 'left' | 'bottom' | 'right') (ref=[Element])? (INT 'px')?) | - ('height' ('<' | '>') (INT 'px' | 'screen/height')) | - ('width' ('<' | '>') (INT 'px' | 'screen/width@'))); +AlignmentType: + ('horizontally' ('all' | 'top' | 'bottom' | 'centered')) | ('vertically' ('all' | 'left' | 'bottom' | 'right')); Element returns Element: {Element} @@ -84,7 +89,7 @@ XpathSelectorValue returns ecore::EString: XPATH_VALUE; terminal SECTION_TAG returns ecore::EString: - '@on' TEXT_VALUE ; + '@on' TEXT_VALUE; terminal SECTION_LABEL returns ecore::EString: '=' TEXT_VALUE '=';