|
1 | 1 | import { test } from 'vitest'
|
2 |
| -import { findClassListsInHtmlRange, findClassNameAtPosition } from './find' |
3 |
| -import { js, html, pug, createDocument } from './test-utils' |
| 2 | +import { |
| 3 | + findClassListsInHtmlRange, |
| 4 | + findClassNameAtPosition, |
| 5 | + findHelperFunctionsInDocument, |
| 6 | +} from './find' |
| 7 | +import { js, html, pug, createDocument, css } from './test-utils' |
| 8 | +import type { Range } from 'vscode-languageserver-textdocument' |
| 9 | + |
| 10 | +const range = (startLine: number, startCol: number, endLine: number, endCol: number): Range => ({ |
| 11 | + start: { line: startLine, character: startCol }, |
| 12 | + end: { line: endLine, character: endCol }, |
| 13 | +}) |
4 | 14 |
|
5 | 15 | test('class regex works in astro', async ({ expect }) => {
|
6 | 16 | let file = createDocument({
|
@@ -875,3 +885,70 @@ test('Can find class name inside JS/TS functions in <script> tags (Svelte)', asy
|
875 | 885 | },
|
876 | 886 | })
|
877 | 887 | })
|
| 888 | + |
| 889 | +test('Can find helper functions in CSS', async ({ expect }) => { |
| 890 | + let file = createDocument({ |
| 891 | + name: 'file.css', |
| 892 | + lang: 'css', |
| 893 | + settings: { |
| 894 | + tailwindCSS: { |
| 895 | + classFunctions: ['clsx'], |
| 896 | + }, |
| 897 | + }, |
| 898 | + content: ` |
| 899 | + .a { color: theme(foo); } |
| 900 | + .a { color: theme(foo, default); } |
| 901 | + .a { color: theme("foo"); } |
| 902 | + .a { color: theme("foo", default); } |
| 903 | + .a { color: theme(foo / 0.5); } |
| 904 | + .a { color: theme(foo / 0.5, default); } |
| 905 | + .a { color: theme("foo" / 0.5); } |
| 906 | + .a { color: theme("foo" / 0.5, default); } |
| 907 | + `, |
| 908 | + }) |
| 909 | + |
| 910 | + let fns = findHelperFunctionsInDocument(file.state, file.doc) |
| 911 | + |
| 912 | + expect(fns).toEqual([ |
| 913 | + { |
| 914 | + helper: 'theme', |
| 915 | + path: 'foo', |
| 916 | + ranges: { full: range(1, 24, 1, 27), path: range(1, 24, 1, 27) }, |
| 917 | + }, |
| 918 | + { |
| 919 | + helper: 'theme', |
| 920 | + path: 'foo', |
| 921 | + ranges: { full: range(2, 24, 2, 36), path: range(2, 24, 2, 27) }, |
| 922 | + }, |
| 923 | + { |
| 924 | + helper: 'theme', |
| 925 | + path: 'foo', |
| 926 | + ranges: { full: range(3, 24, 3, 29), path: range(3, 25, 3, 28) }, |
| 927 | + }, |
| 928 | + { |
| 929 | + helper: 'theme', |
| 930 | + path: 'foo', |
| 931 | + ranges: { full: range(4, 24, 4, 38), path: range(4, 25, 4, 28) }, |
| 932 | + }, |
| 933 | + { |
| 934 | + helper: 'theme', |
| 935 | + path: 'foo', |
| 936 | + ranges: { full: range(5, 24, 5, 33), path: range(5, 24, 5, 27) }, |
| 937 | + }, |
| 938 | + { |
| 939 | + helper: 'theme', |
| 940 | + path: 'foo', |
| 941 | + ranges: { full: range(6, 24, 6, 42), path: range(6, 24, 6, 27) }, |
| 942 | + }, |
| 943 | + { |
| 944 | + helper: 'theme', |
| 945 | + path: 'foo', |
| 946 | + ranges: { full: range(7, 24, 7, 35), path: range(7, 25, 7, 28) }, |
| 947 | + }, |
| 948 | + { |
| 949 | + helper: 'theme', |
| 950 | + path: 'foo', |
| 951 | + ranges: { full: range(8, 24, 8, 44), path: range(8, 25, 8, 28) }, |
| 952 | + }, |
| 953 | + ]) |
| 954 | +}) |
0 commit comments