From 5841195cdab823a867b0ba3c00df9a154788cdcd Mon Sep 17 00:00:00 2001
From: Manuel Friedli <manuel@fritteli.ch>
Date: Sat, 1 Sep 2018 00:26:35 +0200
Subject: [PATCH] Fixed named for Punycode{De,En}coder and added tests.

---
 src/app/converter-registry.service.ts         |  4 +--
 src/app/converter/punycode-decoder.spec.ts    | 27 +++++++++++++++++++
 ...punycodedecoder.ts => punycode-decoder.ts} |  0
 src/app/converter/punycode-encoder.spec.ts    | 27 +++++++++++++++++++
 ...punycodeencoder.ts => punycode-encoder.ts} |  0
 5 files changed, 56 insertions(+), 2 deletions(-)
 create mode 100644 src/app/converter/punycode-decoder.spec.ts
 rename src/app/converter/{punycodedecoder.ts => punycode-decoder.ts} (100%)
 create mode 100644 src/app/converter/punycode-encoder.spec.ts
 rename src/app/converter/{punycodeencoder.ts => punycode-encoder.ts} (100%)

diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts
index f99639f..55dbf4e 100644
--- a/src/app/converter-registry.service.ts
+++ b/src/app/converter-registry.service.ts
@@ -9,8 +9,8 @@ import {HTMLEntitiesDecoder} from './converter/htmlentities-decoder';
 import {HTMLEntitiesEncoder} from './converter/htmlentities-encoder';
 import {Injectable} from '@angular/core';
 import {NativeLibraryWrapperService} from './native-library-wrapper.service';
-import {PunycodeDecoder} from './converter/punycodedecoder';
-import {PunycodeEncoder} from './converter/punycodeencoder';
+import {PunycodeDecoder} from './converter/punycode-decoder';
+import {PunycodeEncoder} from './converter/punycode-encoder';
 import {QuotedPrintableDecoder} from './converter/quotedprintabledecoder';
 import {QuotedPrintableEncoder} from './converter/quotedprintableencoder';
 import {ROT13Converter} from './converter/rot13converter';
diff --git a/src/app/converter/punycode-decoder.spec.ts b/src/app/converter/punycode-decoder.spec.ts
new file mode 100644
index 0000000..12c21e9
--- /dev/null
+++ b/src/app/converter/punycode-decoder.spec.ts
@@ -0,0 +1,27 @@
+import {PunycodeDecoder} from './punycode-decoder';
+import {NativeLibraryWrapperService} from '../native-library-wrapper.service';
+import createSpyObj = jasmine.createSpyObj;
+import Spy = jasmine.Spy;
+
+describe('PunycodeDecoder', () => {
+  let nativeWrapperSpy: Partial<NativeLibraryWrapperService>;
+  let decodeSpy: Spy;
+  beforeEach(() => {
+    nativeWrapperSpy = {punycode: createSpyObj(['decode'])};
+    decodeSpy = nativeWrapperSpy.punycode.decode as Spy;
+  });
+  it('should create an instance', () => {
+    expect(new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService)).toBeTruthy();
+  });
+  it('should have the id "decodepunycode"', () => {
+    expect(new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService).getId()).toEqual('decodepunycode');
+  });
+  it('should call through to the native punycode decoder', () => {
+    const testInput = 'My input';
+    const expectedOutput = 'It worked';
+    decodeSpy.and.returnValue(expectedOutput);
+    const result: string = new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService).convert(testInput);
+    expect(result).toEqual(expectedOutput);
+    expect(decodeSpy).toHaveBeenCalledWith(testInput);
+  });
+});
diff --git a/src/app/converter/punycodedecoder.ts b/src/app/converter/punycode-decoder.ts
similarity index 100%
rename from src/app/converter/punycodedecoder.ts
rename to src/app/converter/punycode-decoder.ts
diff --git a/src/app/converter/punycode-encoder.spec.ts b/src/app/converter/punycode-encoder.spec.ts
new file mode 100644
index 0000000..9da3d8a
--- /dev/null
+++ b/src/app/converter/punycode-encoder.spec.ts
@@ -0,0 +1,27 @@
+import {NativeLibraryWrapperService} from '../native-library-wrapper.service';
+import {PunycodeEncoder} from './punycode-encoder';
+import createSpyObj = jasmine.createSpyObj;
+import Spy = jasmine.Spy;
+
+describe('PunycodeEncoder', () => {
+  let nativeWrapperSpy: Partial<NativeLibraryWrapperService>;
+  let encodeSpy: Spy;
+  beforeEach(() => {
+    nativeWrapperSpy = {punycode: createSpyObj(['encode'])};
+    encodeSpy = nativeWrapperSpy.punycode.encode as Spy;
+  });
+  it('should create an instance', () => {
+    expect(new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService)).toBeTruthy();
+  });
+  it('should have the id "encodepunycode"', () => {
+    expect(new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService).getId()).toEqual('encodepunycode');
+  });
+  it('should call through to the native punycode encoder', () => {
+    const testInput = 'My input';
+    const expectedOutput = 'It worked';
+    encodeSpy.and.returnValue(expectedOutput);
+    const result: string = new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService).convert(testInput);
+    expect(result).toEqual(expectedOutput);
+    expect(encodeSpy).toHaveBeenCalledWith(testInput);
+  });
+});
diff --git a/src/app/converter/punycodeencoder.ts b/src/app/converter/punycode-encoder.ts
similarity index 100%
rename from src/app/converter/punycodeencoder.ts
rename to src/app/converter/punycode-encoder.ts