Skip to content

Commit

Permalink
Add tests surrounding trim function used in wsdl parsing.
Browse files Browse the repository at this point in the history
Use native string.trim instead of regex replace for performance.

remove log line.
fix quotes in tests.
  • Loading branch information
shellicar committed Mar 28, 2023
1 parent 4660fa2 commit 499395a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/wsdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ const debug = debugBuilder('node-soap');

const XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance';

const trimLeft = /^[\s\xA0]+/;
const trimRight = /[\s\xA0]+$/;

function trim(text) {
return text.replace(trimLeft, '').replace(trimRight, '');
export function trim(text) {
return text.trim();
}

function deepMerge<A, B>(destination: A, source: B): A & B {
Expand Down
30 changes: 30 additions & 0 deletions test/trim-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
trim = require('../lib/wsdl/index.js').trim
var assert = require('assert');

it('should trim correctly', async () => {
describe('removes whitespace', async () => {
const input = ' \n <> \n ';
const expected = '<>';

verify(input, expected);
})

describe('removes non breaking space', async () => {
const input = '\xA0<>';
const expected = '<>';

verify(input, expected);
});

describe('removes all', async () => {
const input = '\xA0\n \t<\n\t\xA0>\t \n \xA0';
const expected = '<\n\t\xA0>';

verify(input, expected);
});
})

function verify(input, expected) {
const actual = trim(input);
assert(actual === expected, `${actual} != ${expected}`);
}

0 comments on commit 499395a

Please sign in to comment.