Skip to content

Commit

Permalink
Merge pull request ntix#41 from MrAntix/main
Browse files Browse the repository at this point in the history
fix(int): pass radix
  • Loading branch information
ntix authored Feb 9, 2024
2 parents 64e3eb6 + 928e5a0 commit 4c37efc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parsing/numbers/IntParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class IntParser implements IInt.Parser {
return new IntParser(this.parent, this.parseCurrent, this.radix, !this.negate);
}

readonly withRadix = (value?: number) => new IntParser(this.parent, asCurrent(provideParseInt(value), this.negate), this.radix, this.negate);
readonly withRadix = (value?: number) => new IntParser(this.parent, asCurrent(provideParseInt(value), this.negate), value, this.negate);

readonly equals = (value: NumberParsableTypes) => new IntParser(this, asCurrent(provideEquals(parseInt(value, this.radix)), this.negate), this.radix);
readonly anyOf = (values: NumberParsableTypes[] | NumberEnumMap) => new IntParser(this, asCurrent(provideAnyOf(ensureNumberArray(values)), this.negate), this.radix);
Expand Down
8 changes: 8 additions & 0 deletions src/parsing/numbers/numbers-int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ describe('numbers-int', () => {
expect(result.value).toBe(null);
});

it('success binary', () => {
const value = '101';
const result = schema.withRadix(2).parse(value);

expect(result.errors).toEqual(ParseErrors.empty);
expect(result.value).toBe(5);
});

it('failure not int (float)', () => {
const value = 1.2;
const result = schema.parse(value);
Expand Down

0 comments on commit 4c37efc

Please sign in to comment.