import { Query } from '../../query/index.ts'; import { it, expect } from 'vitest' import { parseFile } from '../parseFile.ts' it('parses a file with a single query', () => { const parsed = parseFile('a b c'); expect(parsed.length).toEqual(1); expect((parsed[0] as Query).command).toEqual('a'); expect((parsed[0] as Query).tags[0].attr).toEqual('b'); expect((parsed[0] as Query).tags[1].attr).toEqual('c'); }); it.skip('parses a file with a single query across multiple lines', () => { const parsed = parseFile(` include ( a b c ) `); expect(parsed.length).toEqual(1); expect((parsed as any)[0].command).toEqual('include'); expect((parsed as any)[0].tags[0].getValue().t).toEqual('query'); expect((parsed as any)[0].tags[0].getValue().toQueryString()).toEqual('a b c'); }); it('parses a file with multiple queries (seperated by semicolons)', () => { const parsed = parseFile(` a b c; d e f; `); expect(parsed.map((q:any) => q.toQueryString())).toEqual(['a b c', 'd e f']); }); it('parses a file with multiple queries (seperated by newlines)', () => { const parsed = parseFile(` a b c d e f `); expect(parsed.map((q:any) => q.toQueryString())).toEqual(['a b c', 'd e f']); }); it('parses a file with multiline queries (using indentation)', () => { const parsed = parseFile(` a b c d e f `); expect(parsed.map((q:any) => q.toQueryString())).toEqual(['a b c', 'd e f']); }); it('parses another file with indentation', () => { const parsed = parseFile( 'deploy-settings\n' + ' project-name=proj\n' + ' dest-url=http://host\n' + '\n' + 'include src\n' + 'include package.json\n' + 'include tsconfig.json\n' ); expect(parsed.map((q:any) => q.toQueryString())).toEqual( [ 'deploy-settings project-name=proj dest-url=http://host', 'include src', 'include package.json', 'include tsconfig.json' ]) }); it('ignores comment lines that start with #', () => { const parsed = parseFile( ' # this is a comment\n' + 'deploy-settings\n' + ' dest-url=http://host\n' ); expect(parsed.map((q:any) => q.toQueryString())).toEqual([ 'deploy-settings dest-url=http://host' ]); }); it('ignores comment lines inside a nested query', () => { const parsed = parseFile( 'deploy-settings\n' + ' # this is a comment\n' + ' dest-url=http://host\n' ); expect(parsed.map((q:any) => q.toQueryString())).toEqual([ 'deploy-settings dest-url=http://host' ]); });