2024-12-03 09:55:37 +03:00
|
|
|
import type { TlEntryDiff, TlSchemaDiff } from './types.js'
|
2022-06-30 16:32:56 +03:00
|
|
|
|
2024-12-03 09:55:37 +03:00
|
|
|
import { describe, expect, it } from 'vitest'
|
2023-11-09 00:20:43 +03:00
|
|
|
import { generateTlEntriesDifference, generateTlSchemasDifference } from './diff.js'
|
|
|
|
import { parseTlToEntries } from './parse.js'
|
|
|
|
import { parseFullTlSchema } from './schema.js'
|
2021-11-23 00:03:59 +03:00
|
|
|
|
|
|
|
describe('generateTlEntriesDifference', () => {
|
2023-11-09 21:03:52 +03:00
|
|
|
const test = (tl: string[], expected?: TlEntryDiff) => {
|
2021-11-23 00:03:59 +03:00
|
|
|
const e = parseTlToEntries(tl.join('\n'))
|
|
|
|
const res = generateTlEntriesDifference(e[0], e[1])
|
2023-11-09 00:20:43 +03:00
|
|
|
expect(res).toEqual(expected)
|
2021-11-23 00:03:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
it('shows id diff', () => {
|
|
|
|
test(['test#deadbeef = Test;', 'test#baadf00d = Test;'], {
|
|
|
|
name: 'test',
|
|
|
|
id: {
|
2024-08-13 04:53:07 +03:00
|
|
|
old: 0xDEADBEEF,
|
|
|
|
new: 0xBAADF00D,
|
2021-11-23 00:03:59 +03:00
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows comments diff', () => {
|
|
|
|
test(['test = Test;', '// Some comment', 'test = Test;'], {
|
|
|
|
name: 'test',
|
|
|
|
comment: {
|
|
|
|
old: undefined,
|
|
|
|
new: 'Some comment',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows generics diff', () => {
|
|
|
|
test(['test#1 {X:Type} = Test;', 'test#1 = Test;'], {
|
|
|
|
name: 'test',
|
|
|
|
generics: {
|
|
|
|
old: [
|
|
|
|
{
|
|
|
|
name: 'X',
|
|
|
|
type: 'Type',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
new: undefined,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
test(['test#1 {X:Type} = Test;', 'test#1 {Y:Type} = Test;'], {
|
|
|
|
name: 'test',
|
|
|
|
generics: {
|
|
|
|
old: [
|
|
|
|
{
|
|
|
|
name: 'X',
|
|
|
|
type: 'Type',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
new: [
|
|
|
|
{
|
|
|
|
name: 'Y',
|
|
|
|
type: 'Type',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows args diff', () => {
|
2023-09-24 01:32:22 +03:00
|
|
|
test(['test#1 foo:int bar:int egg:flags.0?Egg = Test;', 'test#1 foo:Foo baz:int egg:flags.1?Egg = Test;'], {
|
|
|
|
name: 'test',
|
|
|
|
arguments: {
|
|
|
|
added: [
|
|
|
|
{
|
|
|
|
name: 'baz',
|
|
|
|
type: 'int',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
removed: [
|
|
|
|
{
|
|
|
|
name: 'bar',
|
|
|
|
type: 'int',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
modified: [
|
|
|
|
{
|
|
|
|
name: 'foo',
|
|
|
|
type: {
|
|
|
|
old: 'int',
|
|
|
|
new: 'Foo',
|
2021-11-23 00:03:59 +03:00
|
|
|
},
|
2023-09-24 01:32:22 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'egg',
|
|
|
|
type: {
|
|
|
|
old: 'flags.0?Egg',
|
|
|
|
new: 'flags.1?Egg',
|
2021-11-23 00:03:59 +03:00
|
|
|
},
|
2023-09-24 01:32:22 +03:00
|
|
|
},
|
|
|
|
],
|
2023-06-05 03:30:48 +03:00
|
|
|
},
|
2023-09-24 01:32:22 +03:00
|
|
|
})
|
2021-11-23 00:03:59 +03:00
|
|
|
})
|
2023-11-09 21:03:52 +03:00
|
|
|
|
|
|
|
it('shows args comments diff', () => {
|
|
|
|
test(['// @description a @foo Foo\ntest foo:int = Test;', '// @description a @foo Bar\ntest foo:int = Test;'], {
|
|
|
|
name: 'test',
|
|
|
|
arguments: {
|
|
|
|
added: [],
|
|
|
|
removed: [],
|
|
|
|
modified: [
|
|
|
|
{
|
|
|
|
name: 'foo',
|
|
|
|
comment: {
|
|
|
|
old: 'Foo',
|
|
|
|
new: 'Bar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('throws on incompatible entries', () => {
|
|
|
|
expect(() => test(['test1 = Test;', 'test2 = Test;'])).toThrow()
|
|
|
|
expect(() => test(['test = Test1;', 'test = Test2;'])).toThrow()
|
|
|
|
})
|
2021-11-23 00:03:59 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('generateTlSchemasDifference', () => {
|
2023-11-09 21:03:52 +03:00
|
|
|
const test = (tl1: string[], tl2: string[]) => {
|
2021-11-23 00:03:59 +03:00
|
|
|
const a = parseFullTlSchema(parseTlToEntries(tl1.join('\n')))
|
|
|
|
const b = parseFullTlSchema(parseTlToEntries(tl2.join('\n')))
|
|
|
|
const res: Partial<TlSchemaDiff> = generateTlSchemasDifference(a, b)
|
|
|
|
|
2023-11-09 21:03:52 +03:00
|
|
|
expect(res).toMatchSnapshot()
|
2021-11-23 00:03:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
it('shows added constructors', () => {
|
2023-11-09 21:03:52 +03:00
|
|
|
test(['test1 = Test;'], ['test1 = Test;', 'test2 = Test;'])
|
2021-11-23 00:03:59 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('shows removed constructors', () => {
|
2023-11-09 21:03:52 +03:00
|
|
|
test(['test1 = Test;', 'test2 = Test;'], ['test1 = Test;'])
|
2021-11-23 00:03:59 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('shows modified constructors', () => {
|
2023-11-09 21:03:52 +03:00
|
|
|
test(['test foo:int = Test;'], ['test foo:Foo = Test;'])
|
2021-11-23 00:03:59 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('shows removed unions', () => {
|
2023-11-09 21:03:52 +03:00
|
|
|
test(['test foo:int = Test;', 'test1 = Test1;'], ['test foo:Foo = Test;'])
|
2023-09-24 01:32:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('shows added unions', () => {
|
2023-11-09 21:03:52 +03:00
|
|
|
test(['test foo:int = Test;'], ['test foo:Foo = Test;', 'test1 = Test1;'])
|
2023-09-24 01:32:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('shows modified unions', () => {
|
2023-11-09 21:03:52 +03:00
|
|
|
test(['test foo:int = Test;', 'test1 = Test;'], ['test foo:Foo = Test;', 'test2 = Test;'])
|
2021-11-23 00:03:59 +03:00
|
|
|
|
2023-11-09 21:03:52 +03:00
|
|
|
test(['test foo:int = Test;', 'test1 = Test;'], ['test2 foo:Foo = Test;', 'test3 = Test;'])
|
2023-09-24 01:32:22 +03:00
|
|
|
|
2023-11-09 21:03:52 +03:00
|
|
|
test(['test = Test;', 'test1 = Test;'], ['test = Test1;', 'test1 = Test1;'])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows modified methods', () => {
|
|
|
|
test(['---functions---', 'test = Test;'], ['---functions---', 'test = Test2;'])
|
2021-11-23 00:03:59 +03:00
|
|
|
})
|
|
|
|
})
|