import * as bazinga64 from './index' ; describe ( 'Test Vectors from RFC 4648' , ( ) => { it ( 'handles empty strings' , ( ) => { const text = '' ; const expected = '' ; const encoded = bazinga64 . Encoder . toBase64 ( text ) . asString ; const decoded = bazinga64 . Decoder . fromBase64 ( encoded ) . asString ; expect ( encoded ) . toBe ( expected ) ; expect ( decoded ) . toBe ( text ) ; } ) ; it ( 'handles "f"' , ( ) => { const text = 'f' ; const expected = 'Zg==' ; const encoded = bazinga64 . Encoder . toBase64 ( text ) . asString ; const decoded = bazinga64 . Decoder . fromBase64 ( encoded ) . asString ; expect ( encoded ) . toBe ( expected ) ; expect ( decoded ) . toBe ( text ) ; } ) ; it ( 'handles "fo"' , ( ) => { const text = 'fo' ; const expected = 'Zm8=' ; const encoded = bazinga64 . Encoder . toBase64 ( text ) . asString ; const decoded = bazinga64 . Decoder . fromBase64 ( encoded ) . asString ; expect ( encoded ) . toBe ( expected ) ; expect ( decoded ) . toBe ( text ) ; } ) ; it ( 'handles "foo"' , ( ) => { const text = 'foo' ; const expected = 'Zm9v' ; const encoded = bazinga64 . Encoder . toBase64 ( text ) . asString ; const decoded = bazinga64 . Decoder . fromBase64 ( encoded ) . asString ; expect ( encoded ) . toBe ( expected ) ; expect ( decoded ) . toBe ( text ) ; } ) ; it ( 'foob' , ( ) => { const text = 'foob' ; const expected = 'Zm9vYg==' ; const encoded = bazinga64 . Encoder . toBase64 ( text ) . asString ; const decoded = bazinga64 . Decoder . fromBase64 ( encoded ) . asString ; expect ( encoded ) . toBe ( expected ) ; expect ( decoded ) . toBe ( text ) ; } ) ; it ( 'handles "fooba"' , ( ) => { const text = 'fooba' ; const expected = 'Zm9vYmE=' ; const encoded = bazinga64 . Encoder . toBase64 ( text ) . asString ; const decoded = bazinga64 . Decoder . fromBase64 ( encoded ) . asString ; expect ( encoded ) . toBe ( expected ) ; expect ( decoded ) . toBe ( text ) ; } ) ; it ( 'handles "foobar"' , ( ) => { const text = 'foobar' ; const expected = 'Zm9vYmFy' ; const encoded = bazinga64 . Encoder . toBase64 ( text ) . asString ; const decoded = bazinga64 . Decoder . fromBase64 ( encoded ) . asString ; expect ( encoded ) . toBe ( expected ) ; expect ( decoded ) . toBe ( text ) ; } ) ; } ) ; describe ( 'Special cases' , ( ) => { it ( 'handles malformed URIs' , ( ) => { const serialised = 'owABAaEAWEAfHNWiDY1dv3AmX8F3SVnrKy1T8rO07mMswqDDy4FYzzS7Nw9JWSxFA1Ithb/mJubaZBvhBJgLAIV0amINi5OAAqEAoQBYIDS7Nw9JWSxFA1Ithb/mJubaZBvhBJgLAIV0amINi5OA' ; const decoded = bazinga64 . Decoder . fromBase64 ( serialised ) ; expect ( decoded . asBytes ) . toBeDefined ( ) ; expect ( decoded . asString ) . toBeDefined ( ) ; } ) ; } ) ;