mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* implementation * tests * docs * add uuid_nil, uuid_max * add support for v4 or v7 uuid generation
31 lines
1 KiB
Text
31 lines
1 KiB
Text
use util;
|
|
|
|
function test_uuid( version )
|
|
|
|
var uuid := RandomUUID( version ); // eg. 6d79a467-e483-431c-a9f2-6def3357e893
|
|
if ( uuid != error )
|
|
print( TypeOf( uuid ) );
|
|
foreach ascii in ( CAscZ( uuid ) )
|
|
var char := CChr( ascii );
|
|
if ( _ascii_iter == 15 )
|
|
if ( char != CStr( version ) )
|
|
print( $"Unexpected version at index {_ascii_iter}, expecting '{version}' got '{char}'" );
|
|
endif
|
|
elseif ( _ascii_iter == 9 || _ascii_iter == 14 || _ascii_iter == 19 || _ascii_iter == 24 )
|
|
if ( char != "-" )
|
|
print( $"Unexpected character at index {_ascii_iter}, expecting '-' got '{char}'" );
|
|
endif
|
|
elseif ( ( ascii < 48 /* 0 */ || ascii > 57 /* 9 */ ) && ( ascii < 97 /* a */ &&
|
|
ascii > 102 /* f */ ) )
|
|
print( $"Unexpected character at index {_ascii_iter}, expecting [0-9a-f] got '{char}'" );
|
|
endif
|
|
endforeach
|
|
else
|
|
print( uuid );
|
|
endif
|
|
endfunction
|
|
|
|
test_uuid( 4 );
|
|
test_uuid( 7 );
|
|
test_uuid( 10 );
|
|
test_uuid( "4" );
|