Skip to content

Commit

Permalink
Merge branch 'main' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
afwbkbc committed Jan 11, 2024
2 parents 9e860fc + 6a337b8 commit b5e6871
Show file tree
Hide file tree
Showing 42 changed files with 894 additions and 240 deletions.
Empty file added gse/tests/empty.gls.js
Empty file.
28 changes: 28 additions & 0 deletions gse/tests/exceptions.gls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// this should do nothing
test.assert(true, 'true is false');

let was_caught = false;
try {

// this should do nothing aswell
test.assert(true, 'true is false');

// this should fail but get caught later
test.assert(false, 'assert failed!');

} catch {
TestError: (e) => {
was_caught = true;
}
}
test.assert(was_caught, 'exception was not caught');

was_caught = false;
try {
non_existent_var = 1;
} catch {
ReferenceError: (e) => {
was_caught = true;
}
}
test.assert(was_caught, 'exception was not caught');
17 changes: 17 additions & 0 deletions gse/tests/functions.gls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let var1 = 1;

console.log('here 1', var1);

let func = () => {
console.log('here in 1', var1);
test.assert(var1 == 1);
var1 = 2;
console.log('here in 2', var1);
};

console.log('here 2', var1);
test.assert(var1 == 1);
func();
console.log('here 3', var1);
test.assert(var1 == 2);

31 changes: 31 additions & 0 deletions gse/tests/scopes.gls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
let a = 1;
{
{
{
a++;
}
let a = 5;
{
test.assert(a == 5);
a = 10;
test.assert(a == 10);
}
test.assert(a == 10);
}
test.assert(a++ == 2);
}
test.assert(a == 3);
{
}
{
}
{
}
{
}
{
}
{
}
{
}
132 changes: 132 additions & 0 deletions gse/tests/types.gls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// test script

let a = 5;
a++;
let b = a + 2 * 4;
let c=(a+2)*4;
{
a = 15;
a += 10;
};
c = 123;
c -= 23;

let testmethod1 = (a, b, c) => { return a + b + c; };

let testmethod2 = (a, b, c) => {
/*
this method is a bit different
*/
return
a
+
b
-
c
;
};

let testarr1 = [];
let testarr2 = [ 3, 'TEST', {
key1: 'value1',
key2: 'value2',
} ];
testarr1 []= 'first';
testarr1 []= 'second';
testarr1 []= 1 + 2 + 3;
testarr1 += testarr2;
testarr1 []= testarr2;
let testarr3 = testarr1;
testarr3[1] = 'SECOND';
testarr3[ testmethod2(a, b, c) + 61 ] = 'FIRST';
testarr3[2:5] = testarr1[0:1] + testarr2[0:1];
let testarr4 = testarr3[:3];
testarr4[ c + 1 - 100 : c - 100 + 2 ] = [ 'new first', 'new second' ];

let testobj1 = {};
let testobj2 = {
propertyString: 'STRING',
propertyInt1: 111 + a + b,
propertyInt2: 222,
};
let testobj3 = {
child1: {
child2: {
value: 'CHILD VALUE'
}
},
};
testobj1.propertyInt = testobj2.propertyInt1 + testobj2.propertyInt2;

let d = null;
let x = a > b;

console.log( d );
console.log( d == null );
console.log( x, x == b > c );

console.log( a != b, b != c, c != a, a != a );
console.log( a > b, b > c );
console.log( b >= a, a >= 2, c <= 200, a <= 200 );
console.log( 10 < 10, 10 <= 10, a < a, a <= a );
console.log( true && true, true && false, true || true, true || false );
console.log( (( 5 > 10 ) && ( 2 > 1 )) || (( 5 <= 10 ) && !( 5 > 35 ) && ( 100 >= 20 )) );
console.log(testmethod1(11, b, 20), testmethod2(a, b, c));
let testmethod = testmethod1;
console.log( testmethod( 1, testmethod( 2, testmethod( 3, 3, 3 ), testmethod( 4, 4, 4 ) ), testmethod( 5, 5, testmethod( 6, 6, 6 )) ), 10 );
console.log( testarr1 ); console.log( testarr2 ); console.log( testarr3 ); console.log( testarr4 );
console.log( testarr1[0] ); console.log( testarr1[1] ); console.log( testarr1[0:1] );
console.log( testarr1[5:] ); console.log( testarr1[:3] );
console.log( testarr1[4:5] + testarr1[2:3] );
console.log(testobj3.child1.child2.value);
console.log(testobj1.propertyInt == 272 + c); console.log(testobj1, testobj2);

if ( a > b ) {
console.log( 'YES' );
}
else {
console.log( 'NO' );
};
if ( b > a ) {
console.log( 'YES' );
}
else {
console.log( 'NO' );
};
if ( false ) { console.log( 'FALSE' ); };
if ( false ) {
console.log('FAIL');
} elseif ( false ) {
console.log( 'FAIL' );
} elseif ( true ) {
console.log( 'OK' );
} else {
console.log( 'FAIL' );
};

let i = 0;
while ( i++ < 5 ) {
console.log(i);
};

try {
console.log( 'BEFORE EXCEPTION' ); // should be printed
let failfunc = () => {
console.log('failfunc');
throw TestError('something happened');
};
failfunc();
console.log( 'AFTER EXCEPTION' ); // should not be printed
}
catch {
UnknownError: (e) => {
console.log('shouldnt catch this');
},
TestError: (e) => {
console.log('CAUGHT ' + e.type + ' : ' + e.reason);
console.log(e.backtrace);
}
};

;;;
console.log('bye!');;
14 changes: 14 additions & 0 deletions src/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ Config::Config( const int argc, const char* argv[] ) {
m_debug_flags |= DF_GSE_ONLY | DF_GSE_TESTS;
}
);
parser.AddRule(
"gse-tests-script", "SCRIPT_PATH", "Run only specific GSE test script", AH( this, f_error ) {
if ( !HasDebugFlag( DF_GSE_TESTS ) ) {
f_error( "Gse-tests-related options can only be used after --gse-tests!" );
}
m_debug_flags |= DF_GSE_TESTS_SCRIPT;
m_gse_tests_script = value;
}
);

#endif

try {
Expand Down Expand Up @@ -340,6 +350,10 @@ const game::MapSettings::parameter_t Config::GetQuickstartMapClouds() const {
return m_quickstart_map_clouds;
}

const std::string& Config::GetGSETestsScript() const {
return m_gse_tests_script;
}

#endif

}
10 changes: 7 additions & 3 deletions src/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CLASS( Config, base::Module )
};

#ifdef DEBUG
enum debug_flag_t : uint16_t {
enum debug_flag_t : uint32_t {
DF_NONE = 0,
DF_GDB = 1 << 0,
DF_MAPDUMP = 1 << 1,
Expand All @@ -41,7 +41,8 @@ CLASS( Config, base::Module )
DF_QUIET = 1 << 12,
DF_GSE_ONLY = 1 << 13,
DF_GSE_TESTS = 1 << 14,
DF_GSE_PROMPT_JS = 1 << 15,
DF_GSE_TESTS_SCRIPT = 1 << 15,
DF_GSE_PROMPT_JS = 1 << 16,
};
#endif

Expand Down Expand Up @@ -69,6 +70,7 @@ CLASS( Config, base::Module )
const game::MapSettings::parameter_t GetQuickstartMapErosive() const;
const game::MapSettings::parameter_t GetQuickstartMapLifeforms() const;
const game::MapSettings::parameter_t GetQuickstartMapClouds() const;
const std::string& GetGSETestsScript() const;

#endif

Expand All @@ -90,7 +92,7 @@ CLASS( Config, base::Module )

#ifdef DEBUG

uint16_t m_debug_flags = DF_NONE;
uint32_t m_debug_flags = DF_NONE;
util::Random::state_t m_quickstart_seed = {};
std::string m_quickstart_mapdump = "";
std::string m_quickstart_mapfile = "";
Expand All @@ -100,6 +102,8 @@ CLASS( Config, base::Module )
game::MapSettings::parameter_t m_quickstart_map_lifeforms = game::MapSettings::MAP_LIFEFORMS_AVERAGE;
game::MapSettings::parameter_t m_quickstart_map_clouds = game::MapSettings::MAP_CLOUDS_AVERAGE;

std::string m_gse_tests_script = "";

#endif
};

Expand Down
Loading

0 comments on commit b5e6871

Please sign in to comment.