polserver/testsuite/escript/unicode/unicode02.src
Kevin Eady 593cfffb83
Add uninit, true, false keywords to grammar (#596)
* Update grammar

* Update expression handling for uninit

* update existing tests

* Add new tests

* Remove fullpath from escriptgrammar generation comment

* fix tests

* Update eScript guide

* Declare escript version 0x11

* Add core-changes

* Add `true` and `false` to grammar

* true/false implementation

* Fix existing tests

* Add new tests

* Update core changes

* add docs

* Fix BooleanValue::describe_to

* bool optimizations

* optimize uninit

* remove unused var assignments

* Update grammar for case labels for uninit, booleans

* Fix case label handling for uninit, true, false

* Tests

* Fix compiler version display v1.1700000017881393 -> v1.17

* optimize boolean binary operations

* fix unary boolean optimizer

* add boolean, uninit optimizer test

* Use new fmt lib apis

* Fix compiler warning

* really fix warning lol

* Add Executor[Module]::getParam for bools, FindSubstance test
2024-01-20 05:38:25 +01:00

203 lines
4 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 2018-04-16 Bodom, ultimate string testing, unicode version
// Trying to include all string-related stuff in this script.
use uo;
use os;
var t := "Нè└└☺";
var sep := "―――――――――――――――――――――――――――――――――――――――――――――";
// pack/unpack
var p := Pack(t);
print( p );
var u := Unpack(p);
print( u );
print( u == t );
print( p != u );
print(sep);
var optests := array{
"1234", "Нè└└☺", "b", "ab", "a", "caterpillar",
array{ "α", "β", "γ", 19 },
dictionary{ "ⅠⅡⅢⅣ" -> "𐄜𐄝𐄞", "eeee" -> 0 }
};
// Binary operators
foreach ot in optests
var tmp;
// comparison
print( "t == " + ot );
print( t == ot );
print( CStr(ot) + " == t " );
print( ot == t );
print( "t != " + ot );
print( t != ot );
print( "t < " + ot );
print( t < ot );
print( "t <= " + ot );
print( t <= ot );
print( "t > " + ot );
print( t > ot );
print( "t >= " + ot );
print( t >= ot );
// arithmetic
print( "t + " + ot );
print( t + ot );
print( CStr(ot) + " + t" );
print( ot + t );
print( "t - " + ot );
print( t - ot );
print( CStr(ot) + " - t" );
print( ot - t );
print( "t * " + ot );
print( t * ot );
print( CStr(ot) + " * t" );
print( ot * t );
print( "t / " + ot );
print( t / ot );
print( CStr(ot) + " / t" );
print( ot / t );
print( "t % " + ot );
print( t % ot );
print( CStr(ot) + " % t" );
print( ot % t );
// arithmetic with assignment
tmp := t;
print( "tmp += " + ot );
tmp += ot;
print( tmp );
tmp := t;
print( "tmp -= " + ot );
tmp -= ot;
print( tmp );
tmp := t;
print( "tmp *= " + ot );
tmp *= ot;
print( tmp );
tmp := t;
print( "tmp /= " + ot );
tmp /= ot;
print( tmp );
tmp := t;
print( "tmp %= " + ot );
tmp %= ot;
print( tmp );
// bitwise
print( "t & " + ot );
print( t & ot );
print( CStr(ot) + " & t" );
print( ot & t );
print( "t | " + ot );
print( t | ot );
print( CStr(ot) + " | t" );
print( ot | t );
print( "t ^ " + ot );
print( t ^ ot );
print( CStr(ot) + " ^ t" );
print( ot ^ t );
print( "t << " + ot );
print( t << ot );
print( CStr(ot) + " << t" );
print( ot << t );
print( "t >> " + ot );
print( t >> ot );
print( CStr(ot) + " >> t" );
print( ot >> t );
// member
tmp := t;
print( "tmp .+ " + ot );
tmp .+ ot;
print( tmp );
tmp := t;
print( "tmp .- " + ot );
tmp .- ot;
print( tmp );
tmp := t;
// subscript
print( "t[" + ot + "]" );
print( t[ot] );
print(sep);
endforeach
// Unary operators
print( "~ t" );
print( ~ t );
print(sep);
// Cast
print(CAsc(t));
print(CAscZ(t));
print(CChr(t));
print(CChrZ(t));
print(CDbl(t));
print(CInt(t));
print(CStr(t));
print(sep);
// substring
print(t[0,1]);
print(t[1,99]);
print(t[1,0]);
print(t[1,10]);
print(t[2,2]);
print(t["└└"]);
var tmp := t;
tmp["└└"] := "__";
print(tmp);
print(sep);
// is true
if( t )
print("t is true");
else
print("t is false");
endif
if( "" )
print("\"\" is true");
else
print("\"\" is false");
endif
if( "0" )
print("0 is true");
else
print("0 is false");
endif
print(sep);
// manipulation functions
print( Compare(t, "bè└└☺", 2, 3, 2, 3) );
print( Find(t, "└└", 1) );
print( Len(t) );
print( Lower("Здраво!") );
print( SplitWords("ⅠⅡⅢ 456 789", " ", 1) );
print( StrReplace(t, "└└", "__") );
print( SubStr(t, 2, 2) );
print( SubStrReplace(t, "XXXXXX", 2, 3) );
print( Trim(" Ћао ") );
print( Upper("Здраво!") );
print(sep);
// methods
print( t.length() );
print(t);
print(t.find("è"));
print(t.upper());
print(t.lower());
print("{:x}".format(10));
print("{:#x}".format(10));
print("You hàve {} ☉ coins".format(120));
print("{} hits {} for {} of ☠".format("John", "Bob", 120));
print("You hit {2} for {1} ☠".format(120, "John Doe"));
print("⚗ {1.spell_name} requires reagents: {1.reagents}".format(struct{spell_name:="Firè Wrath", reagents:="Ba, Bm, Ga"}));
print("{name} you ⚔ level {level}".format(struct{name:="Jane Doe", level:=4}));
print(sep);
// check that t is unaltered
print(t);