MCPcopy Create free account
hub / github.com/docker/docker-language-server / TestIsInsideRange

Function TestIsInsideRange

internal/bake/hcl/completion_test.go:692–748  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

690}
691
692func TestIsInsideRange(t *testing.T) {
693 testCases := []struct {
694 name string
695 hclRange hcl.Range
696 position protocol.Position
697 isInside bool
698 }{
699 {
700 name: "start.line < line && line < end.line",
701 hclRange: hcl.Range{Start: hcl.Pos{Line: 1, Column: 5}, End: hcl.Pos{Line: 3, Column: 5}},
702 position: protocol.Position{Line: 1, Character: 14}, // line 2 between lines 1 and 3
703 isInside: true,
704 },
705 {
706 name: "start.line < line && line == end.line && character > end.column",
707 hclRange: hcl.Range{Start: hcl.Pos{Line: 1, Column: 5}, End: hcl.Pos{Line: 3, Column: 5}},
708 position: protocol.Position{Line: 2, Character: 14}, // character 14 is greater than 5
709 isInside: false,
710 },
711 {
712 name: "start.line < line && line == end.line && character < end.column",
713 hclRange: hcl.Range{Start: hcl.Pos{Line: 1, Column: 5}, End: hcl.Pos{Line: 3, Column: 5}},
714 position: protocol.Position{Line: 2, Character: 2}, // 2-2 is less than 2-5
715 isInside: true,
716 },
717 {
718 name: "start.line < line && end.line < line",
719 hclRange: hcl.Range{Start: hcl.Pos{Line: 1, Column: 5}, End: hcl.Pos{Line: 3, Column: 5}},
720 position: protocol.Position{Line: 100, Character: 2}, // line is way over
721 isInside: false,
722 },
723 {
724 name: "start.line == line && line < end.line && start.character < character && character > end.character",
725 hclRange: hcl.Range{Start: hcl.Pos{Line: 1, Column: 5}, End: hcl.Pos{Line: 3, Column: 5}},
726 position: protocol.Position{Line: 0, Character: 10}, // 1-10 is within 1-5 and 3-5
727 isInside: true,
728 },
729 {
730 name: "start.line == line && line < end.line && start.character > character && character > end.character",
731 hclRange: hcl.Range{Start: hcl.Pos{Line: 1, Column: 15}, End: hcl.Pos{Line: 3, Column: 5}},
732 position: protocol.Position{Line: 0, Character: 10}, // 1-10 is before 1-10
733 isInside: false,
734 },
735 {
736 name: "start.line > line",
737 hclRange: hcl.Range{Start: hcl.Pos{Line: 2, Column: 0}, End: hcl.Pos{Line: 2, Column: 5}},
738 position: protocol.Position{Line: 0, Character: 0}, // 1-0 is before 2-0
739 isInside: false,
740 },
741 }
742
743 for _, tc := range testCases {
744 t.Run(tc.name, func(t *testing.T) {
745 require.Equal(t, tc.isInside, isInsideRange(tc.hclRange, tc.position))
746 })
747 }
748}
749

Callers

nothing calls this directly

Calls 1

isInsideRangeFunction · 0.85

Tested by

no test coverage detected