Skip to content

String comparison operators #130

Description

@wojciechczerniak

Description

String comparison operators =, <, >, <=, >=, <> are not supported fully. Currently, they have a naive implementation that assumes the JS will handle it correctly:

export function greater(left: number | string | boolean, right: number | string | boolean, eps: number): boolean {
if (typeof left === 'string' || typeof right === 'string') {
return left > right

  • Case sensitive/insensitive config is not used Global settings #58 (default should be insensitive)
  • Culture/locale is not taken under consideration
  • We do not control how special characters and accent characters are handled
A B =A>B (expected) =A>B (result)
a A false true
aa AA false true
aA aa false false
Aa aa false false

Steps to reproduce

  it('should correctly compare strings', () => {
    const engine = createEngine([
      ['a', 'A', '=A1>B1'],
      ['aa', 'AA', '=A2>B2'],
      ['aA', 'aa', '=A3>B3'],
      ['Aa', 'aa', '=A4>B4'],
    ]);

    expect(engine.getCellValue('C1')).toBe(false);
    expect(engine.getCellValue('C2')).toBe(false);
    expect(engine.getCellValue('C3')).toBe(false);
    expect(engine.getCellValue('C4')).toBe(false);
  })

Links

Gnumeric implementation: https://gitlab.gnome.org/GNOME/gnumeric/blob/master/src/value.c#L1674-1685 (they are normalized)
JS comparators: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators
JS localeCompare: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions