2 * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of yosql,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
8 package wtf
.metio
.yosql
.codegen
.blocks
;
10 import org
.junit
.jupiter
.api
.Assertions
;
11 import org
.junit
.jupiter
.api
.DisplayName
;
12 import org
.junit
.jupiter
.api
.Nested
;
13 import org
.junit
.jupiter
.api
.Test
;
14 import wtf
.metio
.yosql
.testing
.configs
.JavaConfigurations
;
16 @DisplayName("DefaultVariables")
17 class DefaultVariablesTest
{
20 @DisplayName("using default configuration")
21 class JavaDefaultsTest
{
24 @DisplayName("creates variables")
25 void shouldCreateVariable() {
27 final var variables
= new DefaultVariables(JavaConfigurations
.defaults());
30 final var variable
= variables
.inline(String
.class, "test");
33 Assertions
.assertEquals("""
34 final java.lang.String test""", variable
.toString());
38 @DisplayName("creates variables with initializer")
39 void shouldCreateVariableWithInitializer() {
41 final var variables
= new DefaultVariables(JavaConfigurations
.defaults());
44 final var variable
= variables
.inline(String
.class, "test", CodeBlocks
.code("$S", "hello world"));
47 Assertions
.assertEquals("""
48 final var test = "hello world
" """, variable
.toString());
52 @DisplayName("creates variable statements")
53 void shouldCreateVariableStatement() {
55 final var variables
= new DefaultVariables(JavaConfigurations
.defaults());
58 final var variable
= variables
.statement(String
.class, "test", CodeBlocks
.code("$S", "hello world"));
61 Assertions
.assertEquals("""
62 final var test = "hello world
";
63 """, variable
.toString());
69 @DisplayName("using Java 8 configuration")
73 @DisplayName("creates variables")
74 void shouldCreateVariable() {
76 final var variables
= new DefaultVariables(JavaConfigurations
.java8());
79 final var variable
= variables
.inline(String
.class, "test");
82 Assertions
.assertEquals("""
83 final java.lang.String test""", variable
.toString());
87 @DisplayName("creates variables with initializer")
88 void shouldCreateVariableWithInitializer() {
90 final var variables
= new DefaultVariables(JavaConfigurations
.java8());
93 final var variable
= variables
.inline(String
.class, "test", CodeBlocks
.code("$S", "hello world"));
96 Assertions
.assertEquals("""
97 final java.lang.String test = "hello world
" """, variable
.toString());
101 @DisplayName("creates variable statements")
102 void shouldCreateVariableStatement() {
104 final var variables
= new DefaultVariables(JavaConfigurations
.java8());
107 final var variable
= variables
.statement(String
.class, "test", CodeBlocks
.code("$S", "hello world"));
110 Assertions
.assertEquals("""
111 final java.lang.String test = "hello world
";
112 """, variable
.toString());
118 @DisplayName("using Java 9 configuration")
122 @DisplayName("creates variables")
123 void shouldCreateVariable() {
125 final var variables
= new DefaultVariables(JavaConfigurations
.java9());
128 final var variable
= variables
.inline(String
.class, "test");
131 Assertions
.assertEquals("""
132 final java.lang.String test""", variable
.toString());
136 @DisplayName("creates variables with initializer")
137 void shouldCreateVariableWithInitializer() {
139 final var variables
= new DefaultVariables(JavaConfigurations
.java9());
142 final var variable
= variables
.inline(String
.class, "test", CodeBlocks
.code("$S", "hello world"));
145 Assertions
.assertEquals("""
146 final java.lang.String test = "hello world
" """, variable
.toString());
150 @DisplayName("creates variable statements")
151 void shouldCreateVariableStatement() {
153 final var variables
= new DefaultVariables(JavaConfigurations
.java9());
156 final var variable
= variables
.statement(String
.class, "test", CodeBlocks
.code("$S", "hello world"));
159 Assertions
.assertEquals("""
160 final java.lang.String test = "hello world
";
161 """, variable
.toString());
167 @DisplayName("using Java 11 configuration")
171 @DisplayName("creates variables")
172 void shouldCreateVariable() {
174 final var variables
= new DefaultVariables(JavaConfigurations
.java11());
177 final var variable
= variables
.inline(String
.class, "test");
180 Assertions
.assertEquals("""
181 final java.lang.String test""", variable
.toString());
185 @DisplayName("creates variables with initializer")
186 void shouldCreateVariableWithInitializer() {
188 final var variables
= new DefaultVariables(JavaConfigurations
.java11());
191 final var variable
= variables
.inline(String
.class, "test", CodeBlocks
.code("$S", "hello world"));
194 Assertions
.assertEquals("""
195 final var test = "hello world
" """, variable
.toString());
199 @DisplayName("creates variable statements")
200 void shouldCreateVariableStatement() {
202 final var variables
= new DefaultVariables(JavaConfigurations
.java11());
205 final var variable
= variables
.statement(String
.class, "test", CodeBlocks
.code("$S", "hello world"));
208 Assertions
.assertEquals("""
209 final var test = "hello world
";
210 """, variable
.toString());
216 @DisplayName("using Java 14 configuration")
220 @DisplayName("creates variables")
221 void shouldCreateVariable() {
223 final var variables
= new DefaultVariables(JavaConfigurations
.java14());
226 final var variable
= variables
.inline(String
.class, "test");
229 Assertions
.assertEquals("""
230 final java.lang.String test""", variable
.toString());
234 @DisplayName("creates variables with initializer")
235 void shouldCreateVariableWithInitializer() {
237 final var variables
= new DefaultVariables(JavaConfigurations
.java14());
240 final var variable
= variables
.inline(String
.class, "test", CodeBlocks
.code("$S", "hello world"));
243 Assertions
.assertEquals("""
244 final var test = "hello world
" """, variable
.toString());
248 @DisplayName("creates variable statements")
249 void shouldCreateVariableStatement() {
251 final var variables
= new DefaultVariables(JavaConfigurations
.java14());
254 final var variable
= variables
.statement(String
.class, "test", CodeBlocks
.code("$S", "hello world"));
257 Assertions
.assertEquals("""
258 final var test = "hello world
";
259 """, variable
.toString());
265 @DisplayName("using Java 16 configuration")
269 @DisplayName("creates variables")
270 void shouldCreateVariable() {
272 final var variables
= new DefaultVariables(JavaConfigurations
.java16());
275 final var variable
= variables
.inline(String
.class, "test");
278 Assertions
.assertEquals("""
279 final java.lang.String test""", variable
.toString());
283 @DisplayName("creates variables with initializer")
284 void shouldCreateVariableWithInitializer() {
286 final var variables
= new DefaultVariables(JavaConfigurations
.java16());
289 final var variable
= variables
.inline(String
.class, "test", CodeBlocks
.code("$S", "hello world"));
292 Assertions
.assertEquals("""
293 final var test = "hello world
" """, variable
.toString());
297 @DisplayName("creates variable statements")
298 void shouldCreateVariableStatement() {
300 final var variables
= new DefaultVariables(JavaConfigurations
.java16());
303 final var variable
= variables
.statement(String
.class, "test", CodeBlocks
.code("$S", "hello world"));
306 Assertions
.assertEquals("""
307 final var test = "hello world
";
308 """, variable
.toString());