Browse Source

Add tests for the newly added string operations

improve-conditional-variables
mohamedsalem401 1 year ago
parent
commit
f6c5ee7b52
  1. 37
      packages/core/test/specs/data_sources/model/conditional_variables/operators/StringOperator.ts

37
packages/core/test/specs/data_sources/model/conditional_variables/operators/StringOperator.ts

@ -52,6 +52,43 @@ describe('StringOperator', () => {
});
});
describe('Operator: equalsIgnoreCase', () => {
test('should return true when left equals right ignoring case', () => {
const operator = new StringOperator(StringOperation.equalsIgnoreCase);
expect(operator.evaluate('Hello World', 'hello world')).toBe(true);
});
test('should return false when left does not equal right ignoring case', () => {
const operator = new StringOperator(StringOperation.equalsIgnoreCase);
expect(operator.evaluate('Hello World', 'hello there')).toBe(false);
});
test('should handle empty strings correctly', () => {
const operator = new StringOperator(StringOperation.equalsIgnoreCase);
expect(operator.evaluate('', '')).toBe(true);
expect(operator.evaluate('Hello', '')).toBe(false);
expect(operator.evaluate('', 'Hello')).toBe(false);
});
});
describe('Operator: trimEquals', () => {
test('should return true when left equals right after trimming', () => {
const operator = new StringOperator(StringOperation.trimEquals);
expect(operator.evaluate(' Hello World ', 'Hello World')).toBe(true);
});
test('should return false when left does not equal right after trimming', () => {
const operator = new StringOperator(StringOperation.trimEquals);
expect(operator.evaluate(' Hello World ', 'Hello there')).toBe(false);
});
test('should handle cases with only whitespace', () => {
const operator = new StringOperator(StringOperation.trimEquals);
expect(operator.evaluate(' ', '')).toBe(true); // Both should trim to empty
expect(operator.evaluate(' ', 'non-empty')).toBe(false);
});
});
describe('Edge Case Tests', () => {
test('should return false for contains with empty right string', () => {
const operator = new StringOperator(StringOperation.contains);

Loading…
Cancel
Save