Skip to content

Commit

Permalink
Add Base64 tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-kulcsar committed Oct 28, 2024
1 parent bbba311 commit dc8807e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
43 changes: 43 additions & 0 deletions base64.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace B64Tests {
export function run(): boolean {
let allPassed: boolean = true

let bytes: Uint8Array = new Uint8Array(5)
bytes.setFromArray([1, 2, 3, 4, 5,])
let b64: string = Base64.encodeBuffer(bytes.buffer)
if (b64 != 'AQIDBAU=') {
game.splash("Base64 test 1a failed.")
allPassed = false
}
let bytesOut: Uint8Array = Base64.decodeBuffer(b64)
if (!areEquivalent2(bytesOut, bytes)) {
game.splash("Base64 test 1b failed.")
allPassed = false
}

b64 = 'foocat=='
let b64Standard: string = Base64.encodeBuffer(Base64.decodeBuffer(b64).buffer)
if (b64Standard != 'foocag==') {
game.splash("Base64 test 2 failed.")
allPassed = false
}

try {
Base64.decodeBuffer('abc')
game.splash("Base64 test 3a failed.")
allPassed = false
} catch {

}

try {
Base64.decodeBuffer('123%')
game.splash("Base64 test 3b failed.")
allPassed = false
} catch {

}

return allPassed
}
}
5 changes: 5 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ if (!DataViewTests.run()) {
allPassed = false
}

// Bas64 tests.
if (!B64Tests.run()) {
allPassed = false
}

if (allPassed) {
game.splash("All tests passed!")
} else {
Expand Down
5 changes: 3 additions & 2 deletions pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"dependencies": {
"device": "*",
"pxt-typed-arrays": "github:robo-technical-group/pxt-typed-arrays#v1.1.0"
"pxt-typed-arrays": "github:robo-technical-group/pxt-typed-arrays#v1.2.0"
},
"files": [
"README.md",
Expand All @@ -13,7 +13,8 @@
"arraybuffer.ts",
"dataview.ts",
"typedarrays.ts",
"common.ts"
"common.ts",
"base64.ts"
],
"testFiles": [
"test.ts"
Expand Down

0 comments on commit dc8807e

Please sign in to comment.