Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions batteries/builtins_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ var Builtins_encoding = map[string]*env.Builtin{
//

// Tests:
// equal { "48656c6c6f20576f726c64" |hex\\decode-string } "Hello World"
// equal { "48656c6c6f20576f726c64" |hex\\decode-string |type? } 'string
// equal { "invalid" |hex\\decode-string |disarm |type? } 'error
// equal { "48656c6c6f20576f726c64" |decode\hex-string } "Hello World"
// equal { "48656c6c6f20576f726c64" |decode\hex-string |type? } 'string
// equal { "invalid" |decode\hex-string |disarm |type? } 'error
// Args:
// * hex-string: hexadecimal string to decode
// Returns:
Expand All @@ -36,20 +36,20 @@ var Builtins_encoding = map[string]*env.Builtin{
decoded, err := hex.DecodeString(hexStr.Value)
if err != nil {
ps.FailureFlag = true
return evaldo.MakeBuiltinError(ps, "Failed to decode hex string: "+err.Error(), "hex\\decode-string")
return evaldo.MakeBuiltinError(ps, "Failed to decode hex string: "+err.Error(), "decode\\hex-string")
}
return *env.NewString(string(decoded))
default:
ps.FailureFlag = true
return evaldo.MakeArgError(ps, 1, []env.Type{env.StringType}, "hex\\decode-string")
return evaldo.MakeArgError(ps, 1, []env.Type{env.StringType}, "decode\\hex-string")
}
},
},

// Tests:
// equal { "Hello World" |hex\\encode-string } "48656c6c6f20576f726c64"
// equal { "Hello World" |hex\\encode-string |type? } 'string
// equal { "" |hex\\encode-string } ""
// equal { "Hello World" |encode\hex-string } "48656c6c6f20576f726c64"
// equal { "Hello World" |encode\hex-string |type? } 'string
// equal { "" |encode\hex-string } ""
// Args:
// * string: string to encode
// Returns:
Expand All @@ -65,15 +65,15 @@ var Builtins_encoding = map[string]*env.Builtin{
return *env.NewString(encoded)
default:
ps.FailureFlag = true
return evaldo.MakeArgError(ps, 1, []env.Type{env.StringType}, "hex\\encode-string")
return evaldo.MakeArgError(ps, 1, []env.Type{env.StringType}, "encode\\hex-string")
}
},
},

// Tests:
// equal { " 70 44 01 4b \n 55 50 4e 51 " |hex\\clean-string } "7044014b55504e51"
// equal { "70 44 01 4b\t55 50 4e 51\r\n52 0a" |hex\\clean-string } "7044014b55504e51520a"
// equal { "7044014b55504e51520a" |hex\\clean-string } "7044014b55504e51520a"
// equal { " 70 44 01 4b \n 55 50 4e 51 " |clean\hex-string } "7044014b55504e51"
// equal { "70 44 01 4b\t55 50 4e 51\r\n52 0a" |clean\hex-string } "7044014b55504e51520a"
// equal { "7044014b55504e51520a" |clean\hex-string } "7044014b55504e51520a"
// Args:
// * hex-string: raw hex string with possible whitespace
// Returns:
Expand All @@ -100,14 +100,14 @@ var Builtins_encoding = map[string]*env.Builtin{
return *env.NewString(result)
default:
ps.FailureFlag = true
return evaldo.MakeArgError(ps, 1, []env.Type{env.StringType}, "hex\\clean-string")
return evaldo.MakeArgError(ps, 1, []env.Type{env.StringType}, "clean\\hex-string")
}
},
},

// Tests:
// equal { charmap\\windows-1250 |type? } 'native
// equal { charmap\\windows-1250 |kind? } 'charmap-encoding
// equal { charmap\windows-1250 |type? } 'native
// equal { charmap\windows-1250 |kind? } 'charmap-encoding
// Args:
// * none
// Returns:
Expand All @@ -122,8 +122,8 @@ var Builtins_encoding = map[string]*env.Builtin{
},

// Tests:
// equal { charmap\\iso-8859-1 |type? } 'native
// equal { charmap\\iso-8859-1 |kind? } 'charmap-encoding
// equal { charmap\iso-8859-1 |type? } 'native
// equal { charmap\iso-8859-1 |kind? } 'charmap-encoding
// Args:
// * none
// Returns:
Expand All @@ -138,8 +138,8 @@ var Builtins_encoding = map[string]*env.Builtin{
},

// Tests:
// equal { charmap\\iso-8859-2 |type? } 'native
// equal { charmap\\iso-8859-2 |kind? } 'charmap-encoding
// equal { charmap\iso-8859-2 |type? } 'native
// equal { charmap\iso-8859-2 |kind? } 'charmap-encoding
// Args:
// * none
// Returns:
Expand All @@ -154,8 +154,8 @@ var Builtins_encoding = map[string]*env.Builtin{
},

// Tests:
// equal { charmap\\windows-1252 |type? } 'native
// equal { charmap\\windows-1252 |kind? } 'charmap-encoding
// equal { charmap\windows-1252 |type? } 'native
// equal { charmap\windows-1252 |kind? } 'charmap-encoding
// Args:
// * none
// Returns:
Expand All @@ -170,8 +170,8 @@ var Builtins_encoding = map[string]*env.Builtin{
},

// Tests:
// equal { charmap\\code-page-437 |type? } 'native
// equal { charmap\\code-page-437 |kind? } 'charmap-encoding
// equal { charmap\code-page-437 |type? } 'native
// equal { charmap\code-page-437 |kind? } 'charmap-encoding
// Args:
// * none
// Returns:
Expand All @@ -186,8 +186,8 @@ var Builtins_encoding = map[string]*env.Builtin{
},

// Tests:
// equal { charmap\\code-page-850 |type? } 'native
// equal { charmap\\code-page-850 |kind? } 'charmap-encoding
// equal { charmap\code-page-850 |type? } 'native
// equal { charmap\code-page-850 |kind? } 'charmap-encoding
// Args:
// * none
// Returns:
Expand All @@ -202,8 +202,8 @@ var Builtins_encoding = map[string]*env.Builtin{
},

// Tests:
// equal { charmap\\koi8r |type? } 'native
// equal { charmap\\koi8r |kind? } 'charmap-encoding
// equal { charmap\koi8r |type? } 'native
// equal { charmap\koi8r |kind? } 'charmap-encoding
// Args:
// * none
// Returns:
Expand All @@ -218,8 +218,8 @@ var Builtins_encoding = map[string]*env.Builtin{
},

// Tests:
// equal { charmap\\windows-1250 |charmap-encoding\\new-decoder |type? } 'native
// equal { charmap\\windows-1250 |charmap-encoding\\new-decoder |kind? } 'text-decoder
// equal { charmap\windows-1250 |Decoder |type? } 'native
// equal { charmap\windows-1250 |Decoder |kind? } 'text-decoder
// Args:
// * encoding: charmap encoding as a native value
// Returns:
Expand All @@ -246,8 +246,8 @@ var Builtins_encoding = map[string]*env.Builtin{
},

// Tests:
// equal { charmap\\windows-1250 |charmap-encoding\\new-encoder |type? } 'native
// equal { charmap\\windows-1250 |charmap-encoding\\new-encoder |kind? } 'text-encoder
// equal { charmap\windows-1250 |Encoder |type? } 'native
// equal { charmap\windows-1250 |Encoder |kind? } 'text-encoder
// Args:
// * encoding: charmap encoding as a native value
// Returns:
Expand All @@ -274,9 +274,9 @@ var Builtins_encoding = map[string]*env.Builtin{
},

// Tests:
// equal { charmap\\windows-1250 |charmap-encoding\\new-decoder "Plačilo računa" |text-decoder\\string |contains? "č" } 1
// equal { charmap\\windows-1250 |charmap-encoding\\new-decoder "Hello" |text-decoder\\string } "Hello"
// equal { charmap\\windows-1250 |charmap-encoding\\new-decoder "" |text-decoder\\string } ""
// equal { charmap\windows-1250 |Decoder |Decode "Plačilo računa" |contains? "č" } 1
// equal { charmap\windows-1250 |Decoder |Decode "Hello" } "Hello"
// equal { charmap\windows-1250 |Decoder |Decode "" } ""
// Args:
// * decoder: text decoder as a native value
// * input: string to decode
Expand Down Expand Up @@ -314,8 +314,8 @@ var Builtins_encoding = map[string]*env.Builtin{
},

// Tests:
// equal { charmap\\windows-1250 |charmap-encoding\\new-encoder "Hello" |text-encoder\\string } "Hello"
// equal { charmap\\windows-1250 |charmap-encoding\\new-encoder "Plačilo" |text-encoder\\string |hex\\encode-string } "506c61e8696c6f"
// equal { charmap\windows-1250 |Encoder |Encode "Hello" } "Hello"
// equal { charmap\windows-1250 |Encoder |Encode "Plačilo" |encode\hex-string } "506c61e8696c6f"
// Args:
// * encoder: text encoder as a native value
// * input: string to encode
Expand Down
2 changes: 1 addition & 1 deletion batteries/builtins_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ var Builtins_sqlite = map[string]*env.Builtin{

// Tests:
// equal { Open sqlite://test.db |Query "SELECT * FROM test" |type? } 'table
// Also supports: db .Query { "SELECT * FROM test WHERE id = ?" 123 }
// ; Also supports: db .Query { "SELECT * FROM test WHERE id = ?" 123 }
// Args:
// * db: SQLite database connection
// * sql: SQL query as string, SQL-DSL block, or a block where first value is SQL string and the rest are parameters
Expand Down
1 change: 0 additions & 1 deletion batteries/builtins_structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,6 @@ var Builtins_structures = map[string]*env.Builtin{
//
// ##### Structures ##### "Functions for converting between Rye and Go data structures"
//

// Example: dict [ "name" "John" "age" 30 ] |dict->struct my-struct-ptr
// Args:
// * dict: Rye Dict containing field names and values
Expand Down
2 changes: 1 addition & 1 deletion batteries/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func RegisterBatteries(ps *env.ProgramState) {
evaldo.RegisterBuiltins2(Builtins_bcrypt, ps, "bcrypt")
evaldo.RegisterBuiltins2(Builtins_console, ps, "console")
evaldo.RegisterBuiltinsInContext(Builtins_crypto, ps, "crypto")
evaldo.RegisterBuiltinsInContext(Builtins_encoding, ps, "encoding")
evaldo.RegisterBuiltins2(Builtins_encoding, ps, "encoding")
evaldo.RegisterBuiltinsInContext(Builtins_math, ps, "math")
evaldo.RegisterBuiltinsInContext(Builtins_os, ps, "os")
evaldo.RegisterBuiltinsInContext(Builtins_pipes, ps, "pipes")
Expand Down
3 changes: 3 additions & 0 deletions evaldo/builtins_base_mth.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ func Mth_EvalDirect(ps *env.ProgramState) env.Object {
// ---------------------------------------------------------------------------

var builtins_mth = map[string]*env.Builtin{
//
// ##### Fast Math ##### "Fast infix math evaluator"
//
// Tests:
// equal { mth { 1 + 2 } } 3
// equal { mth { 2 + 3 * 4 } } 14
Expand Down
20 changes: 10 additions & 10 deletions evaldo/builtins_error_handling.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// Error Creation Functions
var ErrorCreationBuiltins = map[string]*env.Builtin{
//
// ##### Failure ###### "Handling failures"
// ##### Failure ##### "Handling failures"
//
// Tests:
// equal { try { fail "error message" } |type? } 'error
Expand Down Expand Up @@ -794,8 +794,8 @@ var ErrorHandlingBuiltins = map[string]*env.Builtin{
},

// Tests:
// equal { fix\\either failure "error" { "fixed" } { "not fixed" } } "fixed"
// equal { fix\\either 5 { "fixed" } { "not fixed" } } "not fixed"
// equal { fix\either failure "error" { "fixed" } { "not fixed" } } "fixed"
// equal { fix\either 5 { "fixed" } { "not fixed" } } "not fixed"
// Args:
// * value: Value to check for failure state
// * error_handler: Block to execute if value is in failure state
Expand Down Expand Up @@ -840,8 +840,8 @@ var ErrorHandlingBuiltins = map[string]*env.Builtin{
},

// Tests:
// equal { 5 |fix\\else { "not fixed" } } "not fixed"
// equal { try { fail "error" |fix\\else { "not fixed" } } |message? } "error"
// equal { 5 |fix\else { "not fixed" } } "not fixed"
// equal { try { fail "error" |fix\else { "not fixed" } } |message? } "error"
// Args:
// * value: Value to check for failure state
// * success_handler: Block to execute if value is not in failure state
Expand Down Expand Up @@ -874,8 +874,8 @@ var ErrorHandlingBuiltins = map[string]*env.Builtin{
},

// Tests:
// equal { 5 |fix\\continue { "error handler" } { "success handler" } } "success handler"
// equal { try { fail "error" |fix\\continue { "error handler" } { "success handler" } } } "error handler"
// equal { 5 |fix\continue { "error handler" } { "success handler" } } "success handler"
// equal { try { fail "error" |fix\continue { "error handler" } { "success handler" } } } "error handler"
// Args:
// * value: Value to check for failure state
// * error_handler: Block to execute if value is in failure state
Expand Down Expand Up @@ -953,9 +953,9 @@ var ErrorHandlingBuiltins = map[string]*env.Builtin{
},

// Tests:
// equal { ^fix\\match failure 404 { 404 { "Not Found" } 500 { "Server Error" } } } "Not Found"
// equal { ^fix\\match failure 500 { 404 { "Not Found" } 500 { "Server Error" } } } "Server Error"
// equal { ^fix\\match failure 403 { 404 { "Not Found" } 500 { "Server Error" } _ { "Unknown Error" } } } "Unknown Error"
// equal { ^fix\match failure 404 { 404 { "Not Found" } 500 { "Server Error" } } } "Not Found"
// equal { ^fix\match failure 500 { 404 { "Not Found" } 500 { "Server Error" } } } "Server Error"
// equal { ^fix\match failure 403 { 404 { "Not Found" } 500 { "Server Error" } _ { "Unknown Error" } } } "Unknown Error"
// Args:
// * error: Error object to match against
// * cases: Block containing error codes and corresponding handler blocks
Expand Down
Loading
Loading