Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hyizhak committed Apr 11, 2024
1 parent f492180 commit fd789d1
Showing 1 changed file with 59 additions and 24 deletions.
83 changes: 59 additions & 24 deletions src/tests/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ else:
expect(toPythonAst(text)).toMatchObject({})
})
test('Nested ternary', () => {
const text = `1 if A else 2 if B else 3\n`;
const text = `1 if a else 2 if b else 3\n`;
expect(toPythonAst(text)).toMatchObject({})
})
});
Expand Down Expand Up @@ -183,105 +183,135 @@ else:
});
});

describe('N-base numbers', () => {
test('Binary number', () => {
const text = `0b101010\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Octal number', () => {
const text = `0o1234567\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Hexadecimal number', () => {
const text = `0xabcdef\n`;
expect(toPythonAst(text)).toMatchObject({})
});
});

describe('Binary operators', () => {
test('Addition', () => {
const text = `a + b\n`;
const text = `1 + 1\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Large Number Addition', () => {
const text = `100000000 ** 100000000 + 1\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Subtraction', () => {
const text = `a - b\n`;
const text = `1 - 1\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Multiplication', () => {
const text = `a * b\n`;
const text = `1 * 1\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Large Number Multiplication', () => {
const text = `100000000 ** 100000000 * 5\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Division', () => {
const text = `a / b\n`;
const text = `1 / 1\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Modulus', () => {
const text = `a % b\n`;
const text = `1 % 1\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Exponent', () => {
const text = `a ** b\n`;
const text = `2 ** 2\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Less than', () => {
const text = `a < b\n`;
const text = `1 < 2\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Greater than', () => {
const text = `a > b\n`;
const text = `2 > 1\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Less than or equal to', () => {
const text = `a <= b\n`;
const text = `1 <= 2\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Greater than or equal to', () => {
const text = `a >= b\n`;
const text = `2 >= 1\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Equality', () => {
const text = `a == b\n`;
const text = `1 == 2\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Inequality', () => {
const text = `a != b\n`;
const text = `1 != 2\n`;
expect(toPythonAst(text)).toMatchObject({})
});
});

describe('Unary operators', () => {
test('Negation', () => {
const text = `-a\n`;
const text = `-1\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Logical NOT', () => {
const text = `not a\n`;
const text = `not 1\n`;
expect(toPythonAst(text)).toMatchObject({})
});
});

describe('Binary logical operators', () => {
test('Logical AND', () => {
const text = `a and b\n`;
const text = `1 and 2\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Logical OR', () => {
const text = `a or b\n`;
const text = `1 or 2\n`;
expect(toPythonAst(text)).toMatchObject({})
});
});

describe('Complex expressions', () => {
test('Function call with arguments', () => {
const text = `function(a, b, c)\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Nested function call', () => {
const text = `function1(function2(a, b), c)\n`;
const text = `
def f1(x, y):
return 1
def f2(x, y):
return y
f1(f2(1, 2), 2)
`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Binary operation with parentheses', () => {
const text = `(a + b) * c\n`;
const text = `(1 + 2) * 3\n`;
expect(toPythonAst(text)).toMatchObject({})
});
});
Expand All @@ -292,6 +322,11 @@ else:
expect(toPythonAst(text)).toMatchObject({})
});

test('Large Number literal', () => {
const text = `1000000000 ** 100000000\n`;
expect(toPythonAst(text)).toMatchObject({})
});

test('Boolean literal True', () => {
const text = `True\n`;
expect(toPythonAst(text)).toMatchObject({})
Expand Down

0 comments on commit fd789d1

Please sign in to comment.