Fixed UTF8{De,En}coder file names and added tests.
This commit is contained in:
parent
d1dde13bef
commit
31c60f12a7
5 changed files with 68 additions and 2 deletions
|
@ -18,8 +18,8 @@ import {URIComponentDecoder} from './converter/uricomponent-decoder';
|
|||
import {URIComponentEncoder} from './converter/uricomponent-encoder';
|
||||
import {URIDecoder} from './converter/uridecoder';
|
||||
import {URIEncoder} from './converter/uriencoder';
|
||||
import {UTF8Decoder} from './converter/utf8decoder';
|
||||
import {UTF8Encoder} from './converter/utf8encoder';
|
||||
import {UTF8Decoder} from './converter/utf8-decoder';
|
||||
import {UTF8Encoder} from './converter/utf8-encoder';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
|
33
src/app/converter/utf8-decoder.spec.ts
Normal file
33
src/app/converter/utf8-decoder.spec.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import {NativeLibraryWrapperService} from '../native-library-wrapper.service';
|
||||
import {UTF8Decoder} from './utf8-decoder';
|
||||
import createSpyObj = jasmine.createSpyObj;
|
||||
import Spy = jasmine.Spy;
|
||||
|
||||
describe('UTF8Decoder', () => {
|
||||
let sut: UTF8Decoder;
|
||||
let nativeWrapperSpy: Partial<NativeLibraryWrapperService>;
|
||||
let decodeSpy: Spy;
|
||||
|
||||
beforeEach(() => {
|
||||
nativeWrapperSpy = {utf8: createSpyObj(['decode'])};
|
||||
decodeSpy = nativeWrapperSpy.utf8.decode as Spy;
|
||||
sut = new UTF8Decoder((nativeWrapperSpy as NativeLibraryWrapperService));
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(sut).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should have the id "decodeutf8"', () => {
|
||||
expect(sut.getId()).toEqual('decodeutf8');
|
||||
});
|
||||
|
||||
it('should call through to the native UTF-8 decoder', () => {
|
||||
const testInput = 'My input';
|
||||
const expectedOutput = 'It worked';
|
||||
decodeSpy.and.returnValue(expectedOutput);
|
||||
const result: string = sut.convert(testInput);
|
||||
expect(result).toEqual(expectedOutput);
|
||||
expect(decodeSpy).toHaveBeenCalledWith(testInput);
|
||||
});
|
||||
});
|
33
src/app/converter/utf8-encoder.spec.ts
Normal file
33
src/app/converter/utf8-encoder.spec.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import {NativeLibraryWrapperService} from '../native-library-wrapper.service';
|
||||
import {UTF8Encoder} from './utf8-encoder';
|
||||
import createSpyObj = jasmine.createSpyObj;
|
||||
import Spy = jasmine.Spy;
|
||||
|
||||
describe('UTF8Encoder', () => {
|
||||
let sut: UTF8Encoder;
|
||||
let nativeWrapperSpy: Partial<NativeLibraryWrapperService>;
|
||||
let encodeSpy: Spy;
|
||||
|
||||
beforeEach(() => {
|
||||
nativeWrapperSpy = {utf8: createSpyObj(['encode'])};
|
||||
encodeSpy = nativeWrapperSpy.utf8.encode as Spy;
|
||||
sut = new UTF8Encoder(nativeWrapperSpy as NativeLibraryWrapperService);
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(sut).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should have the id "encodeutf8"', () => {
|
||||
expect(sut.getId()).toEqual('encodeutf8');
|
||||
});
|
||||
|
||||
it('should call through to the native UTF-8 encoder', () => {
|
||||
const testInput = 'My input';
|
||||
const expectedOutput = 'It worked';
|
||||
encodeSpy.and.returnValue(expectedOutput);
|
||||
const result: string = sut.convert(testInput);
|
||||
expect(result).toEqual(expectedOutput);
|
||||
expect(encodeSpy).toHaveBeenCalledWith(testInput);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue