Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 buildNativeSourceRows,
5 buildNativeSourceTokens,
6 NATIVE_SOURCE_ROW_HEIGHT,
7 NATIVE_SOURCE_STYLE,
8 nativeSourceRowId,
9} from "./nativeSourceFileAdapter";
10import {
11 NATIVE_REVIEW_DIFF_ROW_HEIGHT,
12 NATIVE_REVIEW_DIFF_STYLE,
13} from "../review/nativeReviewDiffAdapter";
14
15describe("nativeSourceFileAdapter", () => {
16 it("uses the same compact code typography as the diff viewer", () => {
17 expect(NATIVE_SOURCE_ROW_HEIGHT).toBe(NATIVE_REVIEW_DIFF_ROW_HEIGHT);
18 expect(NATIVE_SOURCE_STYLE).toMatchObject({
19 rowHeight: NATIVE_REVIEW_DIFF_STYLE.rowHeight,
20 gutterWidth: NATIVE_REVIEW_DIFF_STYLE.gutterWidth,
21 codePadding: NATIVE_REVIEW_DIFF_STYLE.codePadding,
22 textVerticalInset: NATIVE_REVIEW_DIFF_STYLE.textVerticalInset,
23 codeFontSize: NATIVE_REVIEW_DIFF_STYLE.codeFontSize,
24 codeFontWeight: NATIVE_REVIEW_DIFF_STYLE.codeFontWeight,
25 lineNumberFontSize: NATIVE_REVIEW_DIFF_STYLE.lineNumberFontSize,
26 lineNumberFontWeight: NATIVE_REVIEW_DIFF_STYLE.lineNumberFontWeight,
27 });
28 });
29
30 it("maps plain source lines onto context rows with stable line numbers", () => {
31 expect(buildNativeSourceRows(["const value = 1;", "\treturn value;"])).toEqual([
32 {
33 kind: "line",
34 id: nativeSourceRowId(0),
35 fileId: "source-file",
36 content: "const value = 1;",
37 change: "context",
38 newLineNumber: 1,
39 },
40 {
41 kind: "line",
42 id: nativeSourceRowId(1),
43 fileId: "source-file",
44 content: " return value;",
45 change: "context",
46 newLineNumber: 2,
47 },
48 ]);
49 });
50
51 it("maps cached source tokens to the same row identifiers", () => {
52 expect(
53 buildNativeSourceTokens([
54 [{ content: "const", color: "#ff0000", fontStyle: 2 }],
55 [{ content: "\tvalue", color: null, fontStyle: null }],
56 ]),
57 ).toEqual({
58 [nativeSourceRowId(0)]: [{ content: "const", color: "#ff0000", fontStyle: 2 }],
59 [nativeSourceRowId(1)]: [{ content: " value", color: null, fontStyle: null }],
60 });
61 });
62
63 it("clears native tokens while highlighting is unavailable", () => {
64 expect(buildNativeSourceTokens(null)).toEqual({});
65 });
66});