Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { expect, test } from 'vitest'; |
| 2 | |
| 3 | import { classDeclaration } from './Class'; |
| 4 | import { genericParameter } from './GenericParameter'; |
| 5 | import { method } from './Method'; |
| 6 | import { namedType } from './NamedType'; |
| 7 | import { property } from './Property'; |
| 8 | import { stringify } from './stringify'; |
| 9 | |
| 10 | const A = namedType('A'); |
| 11 | |
| 12 | test('empty', () => { |
| 13 | const obj = classDeclaration('MyClass'); |
| 14 | expect(stringify(obj)).toMatchInlineSnapshot(` |
| 15 | "class MyClass {} |
| 16 | " |
| 17 | `); |
| 18 | }); |
| 19 | |
| 20 | test('with property', () => { |
| 21 | const obj = classDeclaration('SomeClass').add(property('foo', A)); |
| 22 | expect(stringify(obj)).toMatchInlineSnapshot(` |
| 23 | "class SomeClass { |
| 24 | foo: A |
| 25 | }" |
| 26 | `); |
| 27 | }); |
| 28 | |
| 29 | test('with method', () => { |
| 30 | const obj = classDeclaration('MyClass').add(method('doThing')); |
| 31 | expect(stringify(obj)).toMatchInlineSnapshot(` |
| 32 | "class MyClass { |
| 33 | doThing(): void |
| 34 | }" |
| 35 | `); |
| 36 | }); |
| 37 | |
| 38 | test('with generic parameter', () => { |
| 39 | const obj = classDeclaration('SomeClass') |
| 40 | .addGenericParameter(genericParameter('T').extends(namedType('U'))) |
| 41 | .add(property('foo', A)); |
| 42 | expect(stringify(obj)).toMatchInlineSnapshot(` |
| 43 | "class SomeClass<T extends U> { |
| 44 | foo: A |
| 45 | }" |
| 46 | `); |
| 47 | }); |
| 48 | |
| 49 | test('extending the type', () => { |
| 50 | const obj = classDeclaration('SomeClass').extends(namedType('Foo')).add(property('foo', A)); |
| 51 | expect(stringify(obj)).toMatchInlineSnapshot(` |
| 52 | "class SomeClass extends Foo { |
| 53 | foo: A |
| 54 | }" |
| 55 | `); |
| 56 | }); |
| 57 | |
| 58 | test('extending multiple types', () => { |
| 59 | const obj = classDeclaration('SomeClass') |
| 60 | .extends(namedType('Foo')) |
| 61 | .extends(namedType('Bar')) |
| 62 | .add(property('foo', A)); |
| 63 | expect(stringify(obj)).toMatchInlineSnapshot(` |
| 64 | "class SomeClass extends Foo, Bar { |
| 65 | foo: A |
| 66 | }" |
| 67 | `); |
| 68 | }); |