Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ include::{extdocdir}/nl.esi.xtext.types.adoc[leveloffset=2]

include::{extdocdir}/nl.esi.xtext.expressions.adoc[leveloffset=2]
include::{extdocdir}/expression-functions-framework-design.adoc[leveloffset=2]

include::{extdocdir}/nl.esi.xtext.actions.adoc[leveloffset=2]
25 changes: 25 additions & 0 deletions bundles/nl.esi.xtext.actions.tests/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src-gen">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="xtend-gen">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
34 changes: 34 additions & 0 deletions bundles/nl.esi.xtext.actions.tests/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>nl.esi.xtext.actions.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21
18 changes: 18 additions & 0 deletions bundles/nl.esi.xtext.actions.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Manifest-Version: 1.0
Automatic-Module-Name: nl.esi.xtext.actions.tests
Bundle-ManifestVersion: 2
Bundle-Name: Actions Lang Tests
Bundle-Vendor: TNO-ESI
Bundle-Version: 0.3.0.qualifier
Bundle-SymbolicName: nl.esi.xtext.actions.tests;singleton:=true
Bundle-ActivationPolicy: lazy
Require-Bundle: nl.esi.xtext.actions,
org.eclipse.xtext.testing,
org.eclipse.xtext.xbase.testing,
org.eclipse.xtext.xbase.lib;bundle-version="2.36.0"
Import-Package: org.junit.jupiter.api;version="[5.1.0,6.0.0)",
org.junit.jupiter.api.extension;version="[5.1.0,6.0.0)",
org.junit.jupiter.api.function;version="[5.1.0,6.0.0)",
org.opentest4j
Bundle-RequiredExecutionEnvironment: JavaSE-21
Export-Package: nl.esi.xtext.actions.tests;x-internal=true
16 changes: 16 additions & 0 deletions bundles/nl.esi.xtext.actions.tests/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) 2024, 2026 TNO-ESI
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#

source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = .,\
META-INF/
bin.excludes = **/*.xtend
4 changes: 4 additions & 0 deletions bundles/nl.esi.xtext.actions.tests/src-gen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2024, 2026 TNO-ESI
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
/*
* generated by Xtext 2.36.0
*/
package nl.esi.xtext.actions.tests

import com.google.inject.Inject
import nl.esi.xtext.actions.actions.ActionModel
import nl.esi.xtext.common.lang.utilities.EcoreUtil3
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith

@ExtendWith(InjectionExtension)
@InjectWith(ActionsInjectorProvider)
class ActionsParsingTest {
@Inject
ParseHelper<ActionModel> parseHelper

@Test
def void loadModel() {
val result = parseHelper.parse('''
bool test = true
if test then test := false fi
''')
Assertions.assertNotNull(result)
val errors = result.eResource.errors
Assertions.assertTrue(errors.isEmpty, '''Unexpected errors: «errors.join(", ")»''')
}

@Test
def void saveModel() {
val input = '''
int test = abs(-1)
for int i in <int[]>[1,2,3] do test := test + 1 end-for'''
val result = parseHelper.parse(input)
EcoreUtil3.validate(result)

val txt = EcoreUtil3.serialize(result);
Assertions.assertEquals(input, txt)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* Copyright (c) 2024, 2026 TNO-ESI
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package nl.esi.xtext.actions.tests

import com.google.inject.Inject
import nl.esi.xtext.actions.actions.ActionModel
import nl.esi.xtext.common.lang.utilities.EcoreUtil3
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith

@ExtendWith(InjectionExtension)
@InjectWith(ActionsInjectorProvider)
class ActionsValidationTest {
@Inject
ParseHelper<ActionModel> actionParseHelper

// === Assignment Action Tests ===

@Test
def void testAssignmentAction() {
validate('''
int x
x := 5
''')
}

@Test
def void testAssignmentActionIncrement() {
validate('''
int x
x := x + 1
''')
}

// === For Action Tests ===

@Test
def void testForAction() {
validate('''
int[] numbers = <int[]>[1, 2, 3]
int total
for int n in numbers
do
total := total + n
end-for
''')
}

// === If Action Tests ===

@Test
def void testIfActionSimple() {
validate('''
int x
x := 10
int result
if x > 5
then
result := 1
fi
''')
}

@Test
def void testIfActionWithElse() {
validate('''
int x
x := 10
int result
if x > 5
then
result := 1
else
result := 0
fi
''')
}

// === Record Field Assignment Action Tests ===

@Test
def void testRecordFieldAssignment() {
validate('''
record Point { int x, int y }
Point p = Point{x = 0, y = 0}
p.x := 10
p.y := 20
''')
}

@Test
def void testNestedRecordFieldAssignment() {
validate('''
record Inner { int value }
record Outer { Inner inner }
Inner i = Inner{value = 0}
Outer o = Outer{inner = i}
o.inner.value := 42
''')
}

// === Function Call Action Tests ===

@Test
def void testFunctionCallAction() {
validate('''
function int sum(int[] values)
int[] data = <int[]>[1, 2, 3]
sum(data)
''')
}

private def validate(String text) {
val result = actionParseHelper.parse(text)

Assertions.assertNotNull(result)
var errors = result.eResource.errors
Assertions.assertTrue(errors.isEmpty, '''Unexpected parsing errors: «errors.join(", ")»''')
EcoreUtil3.validate(result)
errors = result.eResource.errors
Assertions.assertTrue(errors.isEmpty, '''Unexpected validation errors: «errors.join(", ")»''')
// test serialization
EcoreUtil3.serialize(result)
}
}
4 changes: 4 additions & 0 deletions bundles/nl.esi.xtext.actions.tests/xtend-gen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
Loading
Loading