|
1 | 1 | import { describe, it, expect } from '@jest/globals'; |
2 | | -import { normalizeMethodName } from './helper'; |
| 2 | +import { |
| 3 | + normalizeMethodNameJavascript, |
| 4 | + normalizeMethodNameRust, |
| 5 | + extractParameterNames, |
| 6 | +} from './helper'; |
3 | 7 |
|
4 | | -describe('normalizeMethodName', () => { |
| 8 | +describe('Test normalizeMethodNameJavascript', () => { |
5 | 9 | it('returns the original name if it does not contain a dot', () => { |
6 | | - expect(normalizeMethodName('hello')).toBe('hello'); |
7 | | - expect(normalizeMethodName('foo_bar')).toBe('foo_bar'); |
| 10 | + expect(normalizeMethodNameJavascript('hello')).toBe('hello'); |
| 11 | + expect(normalizeMethodNameJavascript('foo_bar')).toBe('foo_bar'); |
8 | 12 | }); |
9 | 13 |
|
10 | 14 | it('splits and capitalizes correctly with dot', () => { |
11 | | - expect(normalizeMethodName('foo.bar')).toBe('fooBar'); |
12 | | - expect(normalizeMethodName('foo.bar.baz')).toBe('fooBarBaz'); |
| 15 | + expect(normalizeMethodNameJavascript('foo.bar')).toBe('fooBar'); |
| 16 | + expect(normalizeMethodNameJavascript('foo.bar.baz')).toBe('fooBarBaz'); |
13 | 17 | }); |
14 | 18 |
|
15 | 19 | it('capitalizes only subsequent parts', () => { |
16 | | - expect(normalizeMethodName('one.two.three')).toBe('oneTwoThree'); |
| 20 | + expect(normalizeMethodNameJavascript('one.two.three')).toBe('oneTwoThree'); |
17 | 21 | }); |
18 | 22 |
|
19 | 23 | it('handles leading/trailing separators gracefully', () => { |
20 | | - expect(normalizeMethodName('.foo.bar')).toBe('FooBar'); |
21 | | - expect(normalizeMethodName('foo.bar.')).toBe('fooBar'); |
22 | | - expect(normalizeMethodName('..foo..bar..')).toBe('FooBar'); |
| 24 | + expect(normalizeMethodNameJavascript('.foo.bar')).toBe('FooBar'); |
| 25 | + expect(normalizeMethodNameJavascript('foo.bar.')).toBe('fooBar'); |
| 26 | + expect(normalizeMethodNameJavascript('..foo..bar..')).toBe('FooBar'); |
23 | 27 | }); |
24 | 28 |
|
25 | 29 | it('handles empty string', () => { |
26 | | - expect(normalizeMethodName('')).toBe(''); |
| 30 | + expect(normalizeMethodNameJavascript('')).toBe(''); |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +describe('Test normalizeMethodNameRust', () => { |
| 35 | + it('returns the original name if it does not contain a dot', () => { |
| 36 | + expect(normalizeMethodNameRust('hello')).toBe('hello'); |
| 37 | + expect(normalizeMethodNameRust('foo_bar')).toBe('foo_bar'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('splits and capitalizes correctly with dot', () => { |
| 41 | + expect(normalizeMethodNameRust('foo.bar')).toBe('foo_bar'); |
| 42 | + expect(normalizeMethodNameRust('foo.bar.baz')).toBe('foo_bar_baz'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('capitalizes only subsequent parts', () => { |
| 46 | + expect(normalizeMethodNameRust('one.two.three')).toBe('one_two_three'); |
| 47 | + }); |
| 48 | + |
| 49 | + it('handles leading/trailing separators gracefully', () => { |
| 50 | + expect(normalizeMethodNameRust('.foo.bar')).toBe('foo_bar'); |
| 51 | + expect(normalizeMethodNameRust('foo.bar.')).toBe('foo_bar'); |
| 52 | + expect(normalizeMethodNameRust('..foo..bar..')).toBe('foo_bar'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('handles empty string', () => { |
| 56 | + expect(normalizeMethodNameRust('')).toBe(''); |
| 57 | + }); |
| 58 | +}); |
| 59 | + |
| 60 | +describe('Test extractParameterNames', () => { |
| 61 | + it('extracts parameter names from a string with types', () => { |
| 62 | + expect(extractParameterNames('number:int, address: string')).toEqual(['number', 'address']); |
| 63 | + expect(extractParameterNames('id:number, name:string, active:boolean')).toEqual([ |
| 64 | + 'id', |
| 65 | + 'name', |
| 66 | + 'active', |
| 67 | + ]); |
| 68 | + }); |
| 69 | + |
| 70 | + it('handles single parameter', () => { |
| 71 | + expect(extractParameterNames('value:string')).toEqual(['value']); |
| 72 | + }); |
| 73 | + |
| 74 | + it('handles parameters without types', () => { |
| 75 | + expect(extractParameterNames('param1, param2, param3')).toEqual(['param1', 'param2', 'param3']); |
| 76 | + }); |
| 77 | + |
| 78 | + it('handles mixed parameters with and without types', () => { |
| 79 | + expect(extractParameterNames('id:number, name, active:boolean')).toEqual([ |
| 80 | + 'id', |
| 81 | + 'name', |
| 82 | + 'active', |
| 83 | + ]); |
| 84 | + }); |
| 85 | + |
| 86 | + it('handles empty string', () => { |
| 87 | + expect(extractParameterNames('')).toEqual([]); |
| 88 | + }); |
| 89 | + |
| 90 | + it('handles string with only whitespace', () => { |
| 91 | + expect(extractParameterNames(' ')).toEqual([]); |
| 92 | + }); |
| 93 | + |
| 94 | + it('handles parameters with extra whitespace', () => { |
| 95 | + expect(extractParameterNames(' number : int , address : string ')).toEqual([ |
| 96 | + 'number', |
| 97 | + 'address', |
| 98 | + ]); |
| 99 | + }); |
| 100 | + |
| 101 | + it('filters out empty parameter names', () => { |
| 102 | + expect(extractParameterNames('valid:type, , another:type')).toEqual(['valid', 'another']); |
27 | 103 | }); |
28 | 104 | }); |
0 commit comments