github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/ui/dashboard/src/utils/template.test.js (about)

     1  import { buildJQFilter } from "./template";
     2  
     3  describe("buildJQFilter", () => {
     4    test("empty", () => {
     5      expect(buildJQFilter("")).toEqual("");
     6    });
     7  
     8    test("no interpolated expression", () => {
     9      expect(buildJQFilter("simple string")).toEqual(
    10        '(["simple string"] | join(""))'
    11      );
    12    });
    13  
    14    test("basic interpolated expression", () => {
    15      expect(
    16        buildJQFilter("simple string with {{ .embedded }} expression")
    17      ).toEqual(
    18        '(["simple string with ", ( .embedded ), " expression"] | join(""))'
    19      );
    20    });
    21  
    22    test("multiple interpolated expressions", () => {
    23      expect(
    24        buildJQFilter(
    25          "simple string with two {{ .embedded }} expressions {{ .in }} there"
    26        )
    27      ).toEqual(
    28        '(["simple string with two ", ( .embedded ), " expressions ", ( .in ), " there"] | join(""))'
    29      );
    30    });
    31  
    32    test("two interpolated expressions with no spacing", () => {
    33      expect(
    34        buildJQFilter(
    35          "simple string with two {{ .embedded }}{{ .adjacent }} expressions"
    36        )
    37      ).toEqual(
    38        '(["simple string with two ", ( .embedded ), ( .adjacent ), " expressions"] | join(""))'
    39      );
    40    });
    41  
    42    test("three interpolated expressions with no spacing", () => {
    43      expect(
    44        buildJQFilter(
    45          "simple string with three {{ .embedded }}{{ .compact }}{{ .adjacent }} expressions"
    46        )
    47      ).toEqual(
    48        '(["simple string with three ", ( .embedded ), ( .compact ), ( .adjacent ), " expressions"] | join(""))'
    49      );
    50    });
    51  
    52    test("replace single quotes with double quotes", () => {
    53      expect(
    54        buildJQFilter(
    55          "simple string with {{ .embedded | 'foo' }} expression using single quotes"
    56        )
    57      ).toEqual(
    58        '(["simple string with ", ( .embedded | "foo" ), " expression using single quotes"] | join(""))'
    59      );
    60    });
    61  
    62    test("ignore unicode single quote", () => {
    63      expect(
    64        buildJQFilter(
    65          "simple string with {{ .embedded | 'what\\u0027s this?' }} expression using plain + unicode single quotes"
    66        )
    67      ).toEqual(
    68        `(["simple string with ", ( .embedded | "what\\u0027s this?" ), " expression using plain + unicode single quotes"] | join(""))`
    69      );
    70    });
    71  
    72    test("ignore unicode single quote", () => {
    73      expect(
    74        buildJQFilter(
    75          "simple string with {{ .embedded | 'what\\u0027s this?' }} expression using plain + unicode single quotes"
    76        )
    77      ).toEqual(
    78        `(["simple string with ", ( .embedded | "what\\u0027s this?" ), " expression using plain + unicode single quotes"] | join(""))`
    79      );
    80    });
    81  
    82    test("ignore additional open interpolation braces if in expression", () => {
    83      expect(buildJQFilter('string with nested {{ "{{" }} braces')).toEqual(
    84        `(["string with nested ", ( "{{" ), " braces"] | join(""))`
    85      );
    86    });
    87  });