Skip to content

Commit

Permalink
Stubbed out server scope keys
Browse files Browse the repository at this point in the history
  • Loading branch information
bdw429s committed Sep 21, 2023
1 parent 2dde0ba commit 50a3939
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 20 deletions.
5 changes: 5 additions & 0 deletions runtime/src/main/java/ortus/boxlang/runtime/types/Struct.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public Struct() {
this( Type.DEFAULT );
}

public Struct( Map<Object, Object> map ) {
this( Type.DEFAULT );
addAll( map );
}

/**
* --------------------------------------------------------------------------
* Map Interface Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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 );
}

}

0 comments on commit 50a3939

Please sign in to comment.