From 50a3939e6321a6fbd1a9b6933a473f369c827021 Mon Sep 17 00:00:00 2001 From: Brad Wood Date: Thu, 21 Sep 2023 15:53:32 -0500 Subject: [PATCH] Stubbed out server scope keys --- .../ortus/boxlang/runtime/types/Struct.java | 5 ++ .../boxlang/runtime/scopes/BaseScopeTest.java | 41 +++++++++------- .../ortus/boxlang/runtime/scopes/KeyTest.java | 3 +- .../runtime/scopes/ServerScopeTest.java | 49 +++++++++++++++++++ 4 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 runtime/src/test/java/ortus/boxlang/runtime/scopes/ServerScopeTest.java diff --git a/runtime/src/main/java/ortus/boxlang/runtime/types/Struct.java b/runtime/src/main/java/ortus/boxlang/runtime/types/Struct.java index 8fc93ca7e..5e96a6284 100644 --- a/runtime/src/main/java/ortus/boxlang/runtime/types/Struct.java +++ b/runtime/src/main/java/ortus/boxlang/runtime/types/Struct.java @@ -83,6 +83,11 @@ public Struct() { this( Type.DEFAULT ); } + public Struct( Map map ) { + this( Type.DEFAULT ); + addAll( map ); + } + /** * -------------------------------------------------------------------------- * Map Interface Methods diff --git a/runtime/src/test/java/ortus/boxlang/runtime/scopes/BaseScopeTest.java b/runtime/src/test/java/ortus/boxlang/runtime/scopes/BaseScopeTest.java index 8130aa982..409df6353 100644 --- a/runtime/src/test/java/ortus/boxlang/runtime/scopes/BaseScopeTest.java +++ b/runtime/src/test/java/ortus/boxlang/runtime/scopes/BaseScopeTest.java @@ -18,32 +18,35 @@ package ortus.boxlang.runtime.scopes; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import ortus.boxlang.runtime.types.exceptions.KeyNotFoundException; +import ortus.boxlang.runtime.types.Struct; public class BaseScopeTest { - private static BaseScope scope; - - @BeforeAll - public static void setUp() { - scope = new BaseScope( Key.of( "test" ) ); - } - @Test - void testBasicGetAndSet() { - // Test getValue() and setValue() - assertThrows( KeyNotFoundException.class, () -> scope.dereference( Key.of( "InvalidKey" ), false ) ); - - Key key = Key.of( "testKey" ); - Object value = "testValue"; - scope.put( key, value ); - assertThat( scope.get( key ) ).isEqualTo( value ); - assertThat( scope.get( Key.of( "TestKey" ) ) ).isEqualTo( value ); + public void testConstructor() { + IScope scope = new ServerScope(); + + assertThat( scope.size() ).isGreaterThan( 0 ); + assertThat( scope.containsKey( Key.of( "os" ) ) ).isTrue(); + assertThat( scope.containsKey( Key.of( "java" ) ) ).isTrue(); + + assertThat( scope.containsKey( Key.of( "separator" ) ) ).isTrue(); + Struct separator = ( Struct ) scope.get( Key.of( "separator" ) ); + assertThat( separator.containsKey( Key.of( "path" ) ) ).isTrue(); + assertThat( separator.get( Key.of( "path" ) ) ).isEqualTo( System.getProperty( "path.separator", "" ) ); + assertThat( separator.containsKey( Key.of( "file" ) ) ).isTrue(); + assertThat( separator.get( Key.of( "file" ) ) ).isEqualTo( System.getProperty( "file.separator", "" ) ); + assertThat( separator.containsKey( Key.of( "line" ) ) ).isTrue(); + assertThat( separator.get( Key.of( "line" ) ) ).isEqualTo( System.getProperty( "line.separator", "" ) ); + + assertThat( scope.containsKey( Key.of( "system" ) ) ).isTrue(); + Struct system = ( Struct ) scope.get( Key.of( "system" ) ); + assertThat( system.containsKey( Key.of( "environment" ) ) ).isTrue(); + assertThat( system.containsKey( Key.of( "properties" ) ) ).isTrue(); + } } diff --git a/runtime/src/test/java/ortus/boxlang/runtime/scopes/KeyTest.java b/runtime/src/test/java/ortus/boxlang/runtime/scopes/KeyTest.java index 71df120e1..37e6082e2 100644 --- a/runtime/src/test/java/ortus/boxlang/runtime/scopes/KeyTest.java +++ b/runtime/src/test/java/ortus/boxlang/runtime/scopes/KeyTest.java @@ -18,9 +18,10 @@ */ package ortus.boxlang.runtime.scopes; +import static com.google.common.truth.Truth.assertThat; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static com.google.common.truth.Truth.assertThat; public class KeyTest { diff --git a/runtime/src/test/java/ortus/boxlang/runtime/scopes/ServerScopeTest.java b/runtime/src/test/java/ortus/boxlang/runtime/scopes/ServerScopeTest.java new file mode 100644 index 000000000..41b5f39de --- /dev/null +++ b/runtime/src/test/java/ortus/boxlang/runtime/scopes/ServerScopeTest.java @@ -0,0 +1,49 @@ +/** + * [BoxLang] + * + * Copyright [2023] [Ortus Solutions, Corp] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ortus.boxlang.runtime.scopes; + +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertThrows; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import ortus.boxlang.runtime.types.exceptions.KeyNotFoundException; + +public class ServerScopeTest { + + private static BaseScope scope; + + @BeforeAll + public static void setUp() { + scope = new BaseScope( Key.of( "test" ) ); + } + + @Test + void testBasicGetAndSet() { + // Test getValue() and setValue() + assertThrows( KeyNotFoundException.class, () -> scope.dereference( Key.of( "InvalidKey" ), false ) ); + + Key key = Key.of( "testKey" ); + Object value = "testValue"; + scope.put( key, value ); + assertThat( scope.get( key ) ).isEqualTo( value ); + assertThat( scope.get( Key.of( "TestKey" ) ) ).isEqualTo( value ); + } + +}