-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GetTagData(), GetFunctionData() function not implemented, implement in the COMPAT module
- Loading branch information
Showing
6 changed files
with
313 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/ortus/boxlang/modules/compat/bifs/system/GetFunctionData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* [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 ortus.boxlang.modules.compat.util.KeyDictionary; | ||
import ortus.boxlang.runtime.bifs.BIF; | ||
import ortus.boxlang.runtime.bifs.BIFDescriptor; | ||
import ortus.boxlang.runtime.bifs.BoxBIF; | ||
import ortus.boxlang.runtime.context.IBoxContext; | ||
import ortus.boxlang.runtime.scopes.ArgumentsScope; | ||
import ortus.boxlang.runtime.types.Argument; | ||
import ortus.boxlang.runtime.types.Array; | ||
import ortus.boxlang.runtime.types.Struct; | ||
import ortus.boxlang.runtime.types.exceptions.BoxValidationException; | ||
|
||
@BoxBIF | ||
public class GetFunctionData extends BIF { | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public GetFunctionData() { | ||
super(); | ||
declaredArguments = new Argument[] { | ||
new Argument( true, Argument.STRING, KeyDictionary.functionName ) | ||
}; | ||
} | ||
|
||
/** | ||
* Lucee compat: Return information to of a Function as Struct | ||
* | ||
* @param context The context in which the BIF is being invoked. | ||
* @param arguments Argument scope for the BIF. | ||
* | ||
* @argument.functionName The BIF function you want information for (Ex: listLen) | ||
*/ | ||
public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { | ||
// Namespace is ignored, they never completed the other ones in lucee | ||
String functionName = arguments.getAsString( KeyDictionary.functionName ); | ||
BIFDescriptor descriptor = functionService.getGlobalFunction( functionName ); | ||
|
||
if ( descriptor == null ) { | ||
// Throw Validation Exception | ||
throw new BoxValidationException( "Function not found: " + functionName ); | ||
} | ||
|
||
return Struct.of( | ||
"name", functionName, | ||
"status", "implemented", | ||
"description", "", | ||
"keywords", new Array(), | ||
"returnType", "Any", | ||
"argumentType", "fixed", | ||
"argMin", 0, | ||
"argMax", -1, | ||
"type", "java", | ||
"memeber", Struct.of(), | ||
"arguments", descriptor.getArguments() | ||
); | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/ortus/boxlang/modules/compat/bifs/system/GetTagData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* [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 ortus.boxlang.modules.compat.util.KeyDictionary; | ||
import ortus.boxlang.runtime.bifs.BIF; | ||
import ortus.boxlang.runtime.bifs.BoxBIF; | ||
import ortus.boxlang.runtime.components.ComponentDescriptor; | ||
import ortus.boxlang.runtime.context.IBoxContext; | ||
import ortus.boxlang.runtime.scopes.ArgumentsScope; | ||
import ortus.boxlang.runtime.types.Argument; | ||
import ortus.boxlang.runtime.types.Struct; | ||
import ortus.boxlang.runtime.types.exceptions.BoxValidationException; | ||
|
||
@BoxBIF | ||
public class GetTagData extends BIF { | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public GetTagData() { | ||
super(); | ||
declaredArguments = new Argument[] { | ||
new Argument( true, Argument.STRING, KeyDictionary.nameSpaceWithSeperator ), | ||
new Argument( true, Argument.STRING, KeyDictionary.tagName ) | ||
}; | ||
} | ||
|
||
/** | ||
* Lucee compat: Return information to a Tag as Struct | ||
* | ||
* @param context The context in which the BIF is being invoked. | ||
* @param arguments Argument scope for the BIF. | ||
* | ||
* @argument.namespaceWithSeperator The namespace of the tag (Ex: cf) | ||
* | ||
* @argument.tagName The name of the tag (Ex: mail, http, dbinfo, etc) | ||
*/ | ||
public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { | ||
// Namespace is ignored, they never completed the other ones in lucee | ||
String tagName = arguments.getAsString( KeyDictionary.tagName ); | ||
ComponentDescriptor descriptor = componentService.getComponent( tagName ); | ||
|
||
if ( descriptor == null ) { | ||
// Throw Validation Exception | ||
throw new BoxValidationException( "Tag not found: " + tagName ); | ||
} | ||
|
||
return Struct.of( | ||
"nameSpaceSeperator", "", | ||
"nameSpace", "cf", | ||
"name", tagName, | ||
"description", "", | ||
"status", "implemented", | ||
"attributeType", "fixed", | ||
"parseBody", descriptor.allowsBody(), | ||
"bodyType", descriptor.requiresBody() ? "required" : "free", | ||
"attrMin", 0, | ||
"attrMax", 0, | ||
"hasNameAppendix", false, | ||
"attributeCollection", true, | ||
"type", "java", | ||
"attributes", descriptor.getAttributes() | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/test/java/ortus/boxlang/modules/compat/bifs/system/GetFunctionDataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* [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.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; | ||
import ortus.boxlang.runtime.types.IStruct; | ||
|
||
public class GetFunctionDataTest { | ||
|
||
static BoxRuntime instance; | ||
IBoxContext context; | ||
IScope variables; | ||
static Key result = new Key( "result" ); | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
instance = BoxRuntime.getInstance( true ); | ||
} | ||
|
||
@BeforeEach | ||
public void setupEach() { | ||
context = new ScriptingRequestBoxContext( instance.getRuntimeContext() ); | ||
variables = context.getScopeNearby( VariablesScope.name ); | ||
} | ||
|
||
@DisplayName( "It returns tag data" ) | ||
@Test | ||
public void testBIF() { | ||
instance.executeSource( | ||
""" | ||
result = getFunctionData( "listLen" ) | ||
println( result ) | ||
""", | ||
context ); | ||
IStruct data = variables.getAsStruct( result ); | ||
assertThat( data.get( "name" ) ).isEqualTo( "listLen" ); | ||
assertThat( data.get( "description" ) ).isEqualTo( "" ); | ||
assertThat( data.get( "status" ) ).isEqualTo( "implemented" ); | ||
assertThat( data.get( "argMin" ) ).isEqualTo( 0 ); | ||
assertThat( data.get( "argMax" ) ).isEqualTo( -1 ); | ||
assertThat( data.get( "type" ) ).isEqualTo( "java" ); | ||
assertThat( data.getAsStruct( Key.of( "arguments" ) ) ).isNotEmpty(); | ||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
src/test/java/ortus/boxlang/modules/compat/bifs/system/GetTagDataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* [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.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; | ||
import ortus.boxlang.runtime.types.IStruct; | ||
|
||
public class GetTagDataTest { | ||
|
||
static BoxRuntime instance; | ||
IBoxContext context; | ||
IScope variables; | ||
static Key result = new Key( "result" ); | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
instance = BoxRuntime.getInstance( true ); | ||
} | ||
|
||
@BeforeEach | ||
public void setupEach() { | ||
context = new ScriptingRequestBoxContext( instance.getRuntimeContext() ); | ||
variables = context.getScopeNearby( VariablesScope.name ); | ||
} | ||
|
||
@DisplayName( "It returns tag data" ) | ||
@Test | ||
public void testBIF() { | ||
instance.executeSource( | ||
""" | ||
result = getTagData( "cf", "dbinfo" ) | ||
println( result ) | ||
""", | ||
context ); | ||
IStruct data = variables.getAsStruct( result ); | ||
assertThat( data.get( "nameSpaceSeperator" ) ).isEqualTo( "" ); | ||
assertThat( data.get( "nameSpace" ) ).isEqualTo( "cf" ); | ||
assertThat( data.get( "name" ) ).isEqualTo( "dbinfo" ); | ||
assertThat( data.get( "description" ) ).isEqualTo( "" ); | ||
assertThat( data.get( "status" ) ).isEqualTo( "implemented" ); | ||
assertThat( data.get( "attributeType" ) ).isEqualTo( "fixed" ); | ||
assertThat( data.get( "parseBody" ) ).isEqualTo( false ); | ||
assertThat( data.get( "bodyType" ) ).isEqualTo( "free" ); | ||
assertThat( data.get( "attrMin" ) ).isEqualTo( 0 ); | ||
assertThat( data.get( "attrMax" ) ).isEqualTo( 0 ); | ||
assertThat( data.get( "hasNameAppendix" ) ).isEqualTo( false ); | ||
assertThat( data.get( "attributeCollection" ) ).isEqualTo( true ); | ||
assertThat( data.get( "type" ) ).isEqualTo( "java" ); | ||
assertThat( data.getAsStruct( Key.of( "attributes" ) ) ).isNotEmpty(); | ||
} | ||
|
||
} |