diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index af72c8b..12009ab 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,6 @@ # This workflow is used to build releases # It can also be called by other workflows to reuse the release flow. -name: BoxLang Compat Module Release +name: Release on: # If you push to main this will trigger a stable release @@ -22,11 +22,11 @@ on: workflow_dispatch: env: - MODULE_ID: bx-compat - SNAPSHOT: ${{ inputs.snapshot || false }} + MODULE_ID: ${{ github.event.repository.name }} JDK: 21 GRADLE: 8.7 BUILD_ID: ${{ github.run_number }} + SNAPSHOT: ${{ inputs.snapshot || false }} jobs: ############################################# @@ -64,9 +64,16 @@ jobs: id: current_version run: | # Read Version from gradle.properties - echo "VERSION=`grep '^version=' gradle.properties | cut -d'=' -f2`" >> $GITHUB_ENV + TMPVERSION=$(grep '^version=' gradle.properties | cut -d'=' -f2) + # Replace existing prerelease identifier with -snapshot or append -snapshot if none exists + # If we are on the development branch, we always append -snapshot + if [[ "${{ github.ref }}" == "refs/heads/development" ]]; then + TMPVERSION=$(echo $TMPVERSION | sed 's/-.*$//')-snapshot + fi + # Set the version in the environment + echo "VERSION=$TMPVERSION" >> $GITHUB_ENV - # Branche + # Branch echo "Github Ref is $GITHUB_REF" echo "BRANCH=main" >> $GITHUB_ENV @@ -87,8 +94,8 @@ jobs: run: | npm install -g markdownlint-cli markdownlint changelog.md --fix - ./gradlew downloadBoxLang - ./gradlew build -x test --stacktrace --console=plain + gradle downloadBoxLang + gradle build -x test --stacktrace --console=plain - name: Commit Changelog [unreleased] with latest version uses: EndBug/add-and-commit@v9.1.4 @@ -127,16 +134,16 @@ jobs: SOURCE_DIR: "build/distributions" DEST_DIR: "ortussolutions/boxlang-modules/${{ env.MODULE_ID }}/${{ env.VERSION }}" - # - name: Upload API Docs to S3 - # uses: jakejarvis/s3-sync-action@master - # with: - # args: --acl public-read - # env: - # AWS_S3_BUCKET: "apidocs.ortussolutions.com" - # AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} - # AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_ACCESS_SECRET }} - # SOURCE_DIR: "build-coldbox/apidocs" - # DEST_DIR: "" + - name: Upload API Docs to S3 + uses: jakejarvis/s3-sync-action@master + with: + args: --acl public-read + env: + AWS_S3_BUCKET: "apidocs.ortussolutions.com" + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_ACCESS_SECRET }} + SOURCE_DIR: "build/docs/javadoc" + DEST_DIR: "boxlang-modules/${{ env.MODULE_ID }}/${{ env.VERSION }}" - name: Publish to ForgeBox run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 80ed7eb..e246989 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,7 +16,7 @@ Before submitting your contribution, please make sure to take a moment and read ## Code Of Conduct -This project is open source, and as such, the maintainers give their free time to build and maintain the source code held within. They make the code freely available in the hope that it will be of use to other developers and/or businesses. Please be considerate towards maintainers when raising issues or presenting pull requests. **We all follow the Golden Rule: Do to others as you want them to do to you.** +This project is open-source, and as such, the maintainers give their free time to build and maintain the source code held within. They make the code freely available in the hope that it will be of use to other developers and/or businesses. Please be considerate towards maintainers when raising issues or presenting pull requests. **We all follow the Golden Rule: Do to others as you want them to do to you.** - As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. - Participants will be tolerant of opposing views. diff --git a/build.gradle b/build.gradle index f91b5d0..2ee57cf 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,13 @@ ext { branch = System.getenv( 'BRANCH' ) ?: 'development' } +if (branch == 'development') { + // If the branch is 'development', ensure the version ends with '-snapshot' + // This replaces any existing prerelease identifier with '-snapshot' + version = version.contains('-') ? version.replaceAll(/-.*/, '-snapshot') : "${version}-snapshot" + boxlangVersion = boxlangVersion.contains('-') ? boxlangVersion.replaceAll(/-.*/, '-snapshot') : "${boxlangVersion}-snapshot" +} + repositories { mavenLocal() mavenCentral() @@ -32,10 +39,11 @@ dependencies { // Until BoxLang is published to Maven Central // Look for it in the local build directory // You must run `./gradle build -x test` in the BoxLang project - compileOnly files( '../../boxlang/build/distributions/boxlang-' + boxlangVersion + '-all.jar' ) + compileOnly files( '../boxlang/build/libs/boxlang-' + boxlangVersion + '-all.jar' ) compileOnly files( 'src/test/resources/libs/boxlang-' + boxlangVersion + '-all.jar' ) // Testing Dependencies + testImplementation files( '../boxlang/build/libs/boxlang-' + boxlangVersion + '-all.jar' ) testImplementation files( 'src/test/resources/libs/boxlang-' + boxlangVersion + '-all.jar' ) testImplementation "org.junit.jupiter:junit-jupiter:5.+" testImplementation "org.mockito:mockito-core:5.+" diff --git a/changelog.md b/changelog.md index 76ee2ea..5453a79 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- BL-491 New module settings: + +```js +// The CF -> BL AST transpiler settings +// The transpiler is in the core, but will eventually live in this module, so the settings are here. +transpiler = { + // Turn foo.bar into foo.BAR + upperCaseKeys = true, + // Add output=true to functions and classes + forceOutputTrue = true, + // Merged doc comments into actual function, class, and property annotations + mergeDocsIntoAnnotations = true +} +``` + +- BL-449 preserve single quotes +- Added more docs +- Added new BIFS: `getVariable()`, `setVariable()`, `getComponentMetadata()`, `getMetaData()`, `deleteClientVariable()`, `getClientVariablesList()` + +## [1.2.0] - 2024-08-09 + +### Added + - Module should coerce null values to empty string if the `queryNullToEmpty` is set to true, which is the default - `objectLoad(), and objectSave()` aliases for `objectSerialize()` and `objectDeserialize()` respectively. diff --git a/gradle.properties b/gradle.properties index 2196369..60ba71f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ -# Gradle Properties -version=1.2.0 -group=io.boxlang +#Fri Aug 09 20:10:30 UTC 2024 boxlangVersion=1.0.0-beta9 jdkVersion=21 +version=1.3.0 +group=io.boxlang diff --git a/readme.md b/readme.md index 395c0bb..cbba706 100644 --- a/readme.md +++ b/readme.md @@ -49,9 +49,9 @@ The valid engines are `adobe` or `lucee`. By default the engine is `lucee`. Al Depending on which engine you select an interceptor will be loaded that will seed the `server` scope with the appropriate engine details. -## Contributed Functions +## Contributed BIFs -The compat module will contribute the following functions globally: +The compat module will contribute the following built-in functions globally: * `cacheClear` - Learn more here: https://cfdocs.org/cacheClear * `cacheCount` - Learn more here: https://cfdocs.org/cacheCount @@ -73,8 +73,12 @@ The compat module will contribute the following functions globally: * `cacheRemove` - Learn more here: https://cfdocs.org/cacheRemove * `cacheRemoveAll` - Learn more here: https://cfdocs.org/cacheRemoveAll * `cacheSetProperties` - Learn more here: https://cfdocs.org/cacheSetProperties +* `deleteClientVariable` - Learn more here: https://cfdocs.org/deleteClientVariable +* `getClientVariablesList` - Learn more here: https://cfdocs.org/getClientVariablesList * `getComponentMetadata` - Learn more here: https://cfdocs.org/getComponentMetadata * `getMetaData` - Learn more here: https://cfdocs.org/getMetaData +* `getVariable` - Learn more here: https://cfdocs.org/getVariable +* `setVariable` - Learn more here: https://cfdocs.org/setVariable * `systemOutput` - Learn more here: https://cfdocs.org/systemOutput diff --git a/src/build/SetupTemplate.cfc b/src/build/SetupTemplate.cfc deleted file mode 100644 index 1407e7f..0000000 --- a/src/build/SetupTemplate.cfc +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Setup the Module Template according to your needs - */ -component { - - /** - * Constructor - */ - function init(){ - // Setup Pathing - variables.cwd = getCWD().reReplace( "\.$", "" ); - return this; - } - - /** - * Setup the module template - */ - function run(){ - - // remove old .git - //directoryDelete( variables.cwd & ".git", true ); - - // Create new git repo - //command( "!git init" ).run(); - - var moduleName = ask( "What is the human readable name of your module?" ); - if( !len( moduleName ) ){ - error( "Module Name is required" ); - } - var moduleSlug = ask( "What is the slug for your module?" ); - if( !len( moduleSlug ) ){ - error( "Module Slug is required" ); - } - var moduleDescription = ask( "Short description of your module?" ); - if( !len( moduleDescription ) ){ - error( "Module Description is required" ); - } - - command( "tokenReplace" ) - .params( - path = "/#variables.cwd#/**", - token = "BoxLang Compat Module", - replacement = moduleName - ) - .run(); - - command( "tokenReplace" ) - .params( - path = "/#variables.cwd#/**", - token = "bx-compat", - replacement = moduleSlug - ) - .run(); - - command( "tokenReplace" ) - .params( - path = "/#variables.cwd#/**", - token = "Compatibility module for Adobe/Lucee CFML Engines running under BoxLang", - replacement = moduleDescription - ) - .run(); - - // Finalize Message - print - .line() - .boldMagentaLine( "Your module template is now ready for development! Just add the github origin, commit some code and Go rock it!" ) - .toConsole(); - } - -} diff --git a/src/main/bx/ModuleConfig.bx b/src/main/bx/ModuleConfig.bx index 10b3072..d1dccb1 100644 --- a/src/main/bx/ModuleConfig.bx +++ b/src/main/bx/ModuleConfig.bx @@ -86,7 +86,17 @@ isAdobe = false, // This simulates the query to empty value that Adobe/Lucee do when NOT in full null support // We default it to true to simulate Adobe/Lucee behavior - queryNullToEmpty = true + queryNullToEmpty = true, + // The CF -> BL AST transpiler settings + // The transpiler is in the core, but will eventually live in this module, so the settings are here. + transpiler = { + // Turn foo.bar into foo.BAR + upperCaseKeys = true, + // Add output=true to functions and classes + forceOutputTrue = true, + // Merged doc comments into actual function, class, and property annotations + mergeDocsIntoAnnotations = true + } }; /** diff --git a/src/main/java/ortus/boxlang/modules/compat/bifs/struct/DeleteClientVariable.java b/src/main/java/ortus/boxlang/modules/compat/bifs/struct/DeleteClientVariable.java new file mode 100644 index 0000000..cdc39de --- /dev/null +++ b/src/main/java/ortus/boxlang/modules/compat/bifs/struct/DeleteClientVariable.java @@ -0,0 +1,67 @@ +/** + * [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.modules.compat.bifs.struct; + +import java.util.Set; + +import ortus.boxlang.runtime.bifs.BIF; +import ortus.boxlang.runtime.bifs.BoxBIF; +import ortus.boxlang.runtime.context.IBoxContext; +import ortus.boxlang.runtime.scopes.ArgumentsScope; +import ortus.boxlang.runtime.scopes.IScope; +import ortus.boxlang.runtime.scopes.Key; +import ortus.boxlang.runtime.types.Argument; +import ortus.boxlang.runtime.validation.Validator; + +@BoxBIF +public class DeleteClientVariable extends BIF { + + /** + * Name of client scope + */ + private static final Key clientKey = Key.of( "client" ); + + /** + * Constructor + */ + public DeleteClientVariable() { + super(); + declaredArguments = new Argument[] { + new Argument( true, Argument.STRING, Key._NAME, Set.of( Validator.NON_EMPTY ) ) + }; + } + + /** + * Deletes a client variable. Returns true if variable was successfully deleted; false if it was not deleted. + * + * @param context The context in which the BIF is being invoked. + * @param arguments Argument scope for the BIF. + * + * @argument.name The name of the variable to delete. + * + */ + public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { + Key name = Key.of( arguments.getAsString( Key._NAME ) ); + + IScope clientScope = context.getScope( clientKey ); + boolean existed = clientScope.containsKey( name ); + clientScope.remove( name ); + return existed; + } + +} diff --git a/src/main/java/ortus/boxlang/modules/compat/bifs/struct/GetClientVariablesList.java b/src/main/java/ortus/boxlang/modules/compat/bifs/struct/GetClientVariablesList.java new file mode 100644 index 0000000..822dde5 --- /dev/null +++ b/src/main/java/ortus/boxlang/modules/compat/bifs/struct/GetClientVariablesList.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.modules.compat.bifs.struct; + +import java.util.stream.Collectors; + +import ortus.boxlang.runtime.bifs.BIF; +import ortus.boxlang.runtime.bifs.BoxBIF; +import ortus.boxlang.runtime.context.IBoxContext; +import ortus.boxlang.runtime.scopes.ArgumentsScope; +import ortus.boxlang.runtime.scopes.IScope; +import ortus.boxlang.runtime.scopes.Key; + +@BoxBIF +public class GetClientVariablesList extends BIF { + + /** + * Name of client scope + */ + private static final Key clientKey = Key.of( "client" ); + + /** + * Finds the client variables to which a page has write access. Comma-delimited list of non-read-only client variables + * + * @param context The context in which the BIF is being invoked. + * @param arguments Argument scope for the BIF. + * + */ + public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { + IScope clientScope = context.getScope( clientKey ); + return clientScope.getKeysAsStrings().stream().collect( Collectors.joining( "," ) ); + } + +} diff --git a/src/main/java/ortus/boxlang/modules/compat/bifs/system/GetVariable.java b/src/main/java/ortus/boxlang/modules/compat/bifs/system/GetVariable.java new file mode 100644 index 0000000..39c9144 --- /dev/null +++ b/src/main/java/ortus/boxlang/modules/compat/bifs/system/GetVariable.java @@ -0,0 +1,54 @@ +/** + * [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.modules.compat.bifs.system; + +import java.util.Set; + +import ortus.boxlang.runtime.bifs.BIF; +import ortus.boxlang.runtime.bifs.BoxBIF; +import ortus.boxlang.runtime.context.IBoxContext; +import ortus.boxlang.runtime.dynamic.ExpressionInterpreter; +import ortus.boxlang.runtime.scopes.ArgumentsScope; +import ortus.boxlang.runtime.scopes.Key; +import ortus.boxlang.runtime.types.Argument; +import ortus.boxlang.runtime.validation.Validator; + +@BoxBIF +public class GetVariable extends BIF { + + /** + * Constructor + */ + public GetVariable() { + super(); + declaredArguments = new Argument[] { + new Argument( true, Argument.STRING, Key._NAME, Set.of( Validator.NON_EMPTY ) ) + }; + } + + /** + * Retrieves value of a variable + * + * @param context The context in which the BIF is being invoked. + * @param arguments Argument scope for the BIF. + * + * @argument.name The name of the variable to get. + */ + public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { + String name = arguments.getAsString( Key._NAME ); + return ExpressionInterpreter.getVariable( context, name, false ); + } + +} diff --git a/src/main/java/ortus/boxlang/modules/compat/bifs/system/SetVariable.java b/src/main/java/ortus/boxlang/modules/compat/bifs/system/SetVariable.java new file mode 100644 index 0000000..abe371f --- /dev/null +++ b/src/main/java/ortus/boxlang/modules/compat/bifs/system/SetVariable.java @@ -0,0 +1,59 @@ +/** + * [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.modules.compat.bifs.system; + +import java.util.Set; + +import ortus.boxlang.runtime.bifs.BIF; +import ortus.boxlang.runtime.bifs.BoxBIF; +import ortus.boxlang.runtime.context.IBoxContext; +import ortus.boxlang.runtime.dynamic.ExpressionInterpreter; +import ortus.boxlang.runtime.scopes.ArgumentsScope; +import ortus.boxlang.runtime.scopes.Key; +import ortus.boxlang.runtime.types.Argument; +import ortus.boxlang.runtime.validation.Validator; + +@BoxBIF +public class SetVariable extends BIF { + + /** + * Constructor + */ + public SetVariable() { + super(); + declaredArguments = new Argument[] { + new Argument( true, Argument.STRING, Key._NAME, Set.of( Validator.NON_EMPTY ) ), + new Argument( true, Argument.ANY, Key.value ) + }; + } + + /** + * Sets a variable in the name parameter to the value of the value parameter. + * + * @param context The context in which the BIF is being invoked. + * @param arguments Argument scope for the BIF. + * + * @argument.name The name of the variable to set. + * + * @argument.value The value to set the variable to. + */ + public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { + String name = arguments.getAsString( Key._NAME ); + Object value = arguments.get( Key.value ); + ExpressionInterpreter.setVariable( context, name, value ); + return value; + } + +} diff --git a/src/test/java/ortus/boxlang/modules/compat/bifs/struct/GetClientVariablesListTest.java b/src/test/java/ortus/boxlang/modules/compat/bifs/struct/GetClientVariablesListTest.java new file mode 100644 index 0000000..7eb997b --- /dev/null +++ b/src/test/java/ortus/boxlang/modules/compat/bifs/struct/GetClientVariablesListTest.java @@ -0,0 +1,72 @@ +/** + * [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.modules.compat.bifs.struct; + +import static com.google.common.truth.Truth.assertThat; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import ortus.boxlang.runtime.BoxRuntime; +import ortus.boxlang.runtime.context.IBoxContext; +import ortus.boxlang.runtime.context.ScriptingRequestBoxContext; +import ortus.boxlang.runtime.scopes.IScope; +import ortus.boxlang.runtime.scopes.Key; +import ortus.boxlang.runtime.scopes.VariablesScope; + +public class GetClientVariablesListTest { + + static BoxRuntime instance; + IBoxContext context; + IScope variables; + static Key result = new Key( "result" ); + + @BeforeAll + public static void setUp() { + instance = BoxRuntime.getInstance( true ); + } + + @AfterAll + public static void teardown() { + + } + + @BeforeEach + public void setupEach() { + context = new ScriptingRequestBoxContext( instance.getRuntimeContext() ); + variables = context.getScopeNearby( VariablesScope.name ); + } + + @DisplayName( "It get a list of client vars" ) + @Test + @Disabled + public void testGetClientVariablesList() { + instance.executeSource( + """ + result = getClientVariablesList(); + """, + context ); + assertThat( variables.get( result ) ).isEqualTo( "" ); + } + +} diff --git a/src/test/java/ortus/boxlang/modules/compat/bifs/system/GetVariableTest.java b/src/test/java/ortus/boxlang/modules/compat/bifs/system/GetVariableTest.java new file mode 100644 index 0000000..b084663 --- /dev/null +++ b/src/test/java/ortus/boxlang/modules/compat/bifs/system/GetVariableTest.java @@ -0,0 +1,71 @@ +/** + * [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.modules.compat.bifs.system; + +import static com.google.common.truth.Truth.assertThat; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import ortus.boxlang.runtime.BoxRuntime; +import ortus.boxlang.runtime.context.IBoxContext; +import ortus.boxlang.runtime.context.ScriptingRequestBoxContext; +import ortus.boxlang.runtime.scopes.IScope; +import ortus.boxlang.runtime.scopes.Key; +import ortus.boxlang.runtime.scopes.VariablesScope; + +public class GetVariableTest { + + static BoxRuntime instance; + IBoxContext context; + IScope variables; + static Key result = new Key( "result" ); + + @BeforeAll + public static void setUp() { + instance = BoxRuntime.getInstance( true ); + } + + @AfterAll + public static void teardown() { + + } + + @BeforeEach + public void setupEach() { + context = new ScriptingRequestBoxContext( instance.getRuntimeContext() ); + variables = context.getScopeNearby( VariablesScope.name ); + } + + @DisplayName( "It gets a variable" ) + @Test + public void testItGetsAVariable() { + instance.executeSource( + """ + foo = "bar"; + result = getVariable( 'foo' ); + """, + context ); + assertThat( variables.get( result ) ).isEqualTo( "bar" ); + } + +} diff --git a/src/test/java/ortus/boxlang/modules/compat/bifs/system/SetVariableTest.java b/src/test/java/ortus/boxlang/modules/compat/bifs/system/SetVariableTest.java new file mode 100644 index 0000000..867b12f --- /dev/null +++ b/src/test/java/ortus/boxlang/modules/compat/bifs/system/SetVariableTest.java @@ -0,0 +1,71 @@ +/** + * [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.modules.compat.bifs.system; + +import static com.google.common.truth.Truth.assertThat; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import ortus.boxlang.runtime.BoxRuntime; +import ortus.boxlang.runtime.context.IBoxContext; +import ortus.boxlang.runtime.context.ScriptingRequestBoxContext; +import ortus.boxlang.runtime.scopes.IScope; +import ortus.boxlang.runtime.scopes.Key; +import ortus.boxlang.runtime.scopes.VariablesScope; + +public class SetVariableTest { + + static BoxRuntime instance; + IBoxContext context; + IScope variables; + static Key result = new Key( "result" ); + + @BeforeAll + public static void setUp() { + instance = BoxRuntime.getInstance( true ); + } + + @AfterAll + public static void teardown() { + + } + + @BeforeEach + public void setupEach() { + context = new ScriptingRequestBoxContext( instance.getRuntimeContext() ); + variables = context.getScopeNearby( VariablesScope.name ); + } + + @DisplayName( "It sets a variable" ) + @Test + public void testItSetsAVariable() { + instance.executeSource( + """ + result = setVariable( 'foo', "bar" ); + """, + context ); + assertThat( variables.get( result ) ).isEqualTo( "bar" ); + assertThat( variables.get( new Key( "foo" ) ) ).isEqualTo( "bar" ); + } + +}