Skip to content

Commit

Permalink
fix(formatter,cockroachdb): learn floor division operator (#1235)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Badstübner <jonas.badstuebner@hetzner-cloud.de>
jonasbadstuebner authored Nov 2, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 6fd36cd commit 4e4f720
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/formatter/src/core/Tokenizer.ts
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ export default class Tokenizer {
this.WHITESPACE_REGEX = /^(\s+)/u;
this.NUMBER_REGEX = /^((-\s*)?[0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+|([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}))\b/u;
this.AMBIGUOS_OPERATOR_REGEX = /^(\?\||\?&)/u;
this.OPERATOR_REGEX = /^(<=>|!=|<>|>>|<<|==|<=|>=|!<|!>|\|\|\/|\|\/|\|\||~~\*|~~|!~~\*|!~~|~\*|!~\*|!~|:=|=>|&&|@>|<@|#-|@@|@|.)/u;
this.OPERATOR_REGEX = /^(<=>|!=|<>|>>|<<|==|<=|>=|!<|!>|\|\|\/|\|\/|\|\||\/\/|~~\*|~~|!~~\*|!~~|~\*|!~\*|!~|:=|=>|&&|@>|<@|#-|@@|@|.)/u;
this.NO_SPACE_OPERATOR_REGEX = /^(::|->>|->|#>>|#>)/u;

this.BLOCK_COMMENT_REGEX = /^(\/\*[^]*?(?:\*\/|$))/u;
1 change: 1 addition & 0 deletions packages/formatter/test/behavesLikeSqlFormatter.ts
Original file line number Diff line number Diff line change
@@ -371,6 +371,7 @@ export default function behavesLikeSqlFormatter(language?: any) {
expect(format("foo && bar")).toBe("foo && bar");
expect(format("foo := bar")).toBe("foo := bar");
expect(format("foo => bar")).toBe("foo => bar"); // Snowflake, TimescaleDB
expect(format("foo // bar")).toBe("foo // bar"); // CockroachDB floor division
expect(format("foo <=> bar")).toBe("foo <=> bar");
});

0 comments on commit 4e4f720

Please sign in to comment.