on master help sign in
Add Groovy syntax test.
commite6c3f9693131db18a83cb971c7326798d0101c66 authorFelipe Garcia <felipefegar@gmail.com> dateTue 6 Oct 2020, 21:56 (6 years ago) parent85ff81f
2 files changed+154
tests/syntax-tests/highlighted/Groovy/test.groovy+77 tests/syntax-tests/source/Groovy/test.groovy+77
tests/syntax-tests/highlighted/Groovy/test.groovynew file+77
@@ -0,0 +1,77 @@
1+interface Display {
2+ String asText()
3+}
4+
5+trait Entity {
6+ Integer id
7+}
8+
9+class Product implements Entity, Display {
10+ public String name
11+ public Boolean available
12+ public Float price
13+
14+ private String key
15+ protected String data
16+
17+ /**
18+ * Creates a new product instance.
19+ * @param id Product ID.
20+ * @param name Product name.
21+ * @param available Product availability.
22+ * @param price Product price.
23+ * @param key Product key.
24+ * @param data Product internal data.
25+ */
26+ Product(id, name, available, price, key = "key", data = "internal") {
27+ this.id = id
28+ this.name = name
29+ this.available = available
30+ this.price = price
31+ this.key = key
32+ this.data = data
33+ }
34+
35+ /**@
36+ * Returns product data as text.
37+ * @return Data string.
38+ */
39+ String asText() {
40+ return """ID [${id}] Name [${name}] Available [${available}] Price [${price}]"""
41+ }
42+}
43+
44+/* Creates a new product instance */
45+def product = new Product(1, "T-Shirt", true, 15.00)
46+
47+println(product.asText())
48+
49+product.available = false
50+product.price = 0.0
51+
52+// Check values
53+assert product.asText() == "ID [1] Name [T-Shirt] Available [false] Price [0.0]"
54+
55+def factorial(Integer value) {
56+ if (value <= 1) {
57+ return 1
58+ } else {
59+ return value * factorial(value - 1)
60+ }
61+}
62+
63+assert factorial(5) == 120
64+
65+static String join(List<String> list, String separator) {
66+ String data = ""
67+
68+ list.each { item ->
69+ data += item + separator
70+ }
71+
72+ data = data.substring(0, data.length() - 1)
73+
74+ return data
75+}
76+
77+assert join(["g", "r", "o", "o", "v", "y"], " ") == "g r o o v y"
tests/syntax-tests/source/Groovy/test.groovynew file+77
@@ -0,0 +1,77 @@
1+interface Display {
2+ String asText()
3+}
4+
5+trait Entity {
6+ Integer id
7+}
8+
9+class Product implements Entity, Display {
10+ public String name
11+ public Boolean available
12+ public Float price
13+
14+ private String key
15+ protected String data
16+
17+ /**
18+ * Creates a new product instance.
19+ * @param id Product ID.
20+ * @param name Product name.
21+ * @param available Product availability.
22+ * @param price Product price.
23+ * @param key Product key.
24+ * @param data Product internal data.
25+ */
26+ Product(id, name, available, price, key = "key", data = "internal") {
27+ this.id = id
28+ this.name = name
29+ this.available = available
30+ this.price = price
31+ this.key = key
32+ this.data = data
33+ }
34+
35+ /**@
36+ * Returns product data as text.
37+ * @return Data string.
38+ */
39+ String asText() {
40+ return """ID [${id}] Name [${name}] Available [${available}] Price [${price}]"""
41+ }
42+}
43+
44+/* Creates a new product instance */
45+def product = new Product(1, "T-Shirt", true, 15.00)
46+
47+println(product.asText())
48+
49+product.available = false
50+product.price = 0.0
51+
52+// Check values
53+assert product.asText() == "ID [1] Name [T-Shirt] Available [false] Price [0.0]"
54+
55+def factorial(Integer value) {
56+ if (value <= 1) {
57+ return 1
58+ } else {
59+ return value * factorial(value - 1)
60+ }
61+}
62+
63+assert factorial(5) == 120
64+
65+static String join(List<String> list, String separator) {
66+ String data = ""
67+
68+ list.each { item ->
69+ data += item + separator
70+ }
71+
72+ data = data.substring(0, data.length() - 1)
73+
74+ return data
75+}
76+
77+assert join(["g", "r", "o", "o", "v", "y"], " ") == "g r o o v y"