Skip to content

Commit

Permalink
pkg/path: fix path issue
Browse files Browse the repository at this point in the history
Use proper accessor for Conjuncts so that
all necessary conjuncts are visited.

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I501335b9950556979f67c91df6f827991c12378a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202657
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Matthew Sackman <[email protected]>
  • Loading branch information
mpvl committed Oct 18, 2024
1 parent 537f744 commit e9c005d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 275 deletions.
6 changes: 3 additions & 3 deletions internal/core/adt/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,14 +635,14 @@ func (v *Vertex) setParentDone() {

// VisitLeafConjuncts visits all conjuncts that are leafs of the ConjunctGroup tree.
func (v *Vertex) VisitLeafConjuncts(f func(Conjunct) bool) {
visitConjuncts(v.Conjuncts, f)
VisitConjuncts(v.Conjuncts, f)
}

func visitConjuncts(a []Conjunct, f func(Conjunct) bool) bool {
func VisitConjuncts(a []Conjunct, f func(Conjunct) bool) bool {
for _, c := range a {
switch x := c.x.(type) {
case *ConjunctGroup:
if !visitConjuncts(*x, f) {
if !VisitConjuncts(*x, f) {
return false
}
default:
Expand Down
14 changes: 8 additions & 6 deletions internal/core/export/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,15 @@ func (e *exporter) bool(n *adt.Bool) (b *ast.BasicLit) {
return ast.NewBool(n.B)
}

func extractBasic(a []adt.Conjunct) *ast.BasicLit {
for _, v := range a {
if b, ok := v.Source().(*ast.BasicLit); ok {
return &ast.BasicLit{Kind: b.Kind, Value: b.Value}
func extractBasic(a []adt.Conjunct) (lit *ast.BasicLit) {
adt.VisitConjuncts(a, func(c adt.Conjunct) bool {
if b, ok := c.Source().(*ast.BasicLit); ok {
lit = &ast.BasicLit{Kind: b.Kind, Value: b.Value}
return false
}
}
return nil
return true
})
return lit
}

func (e *exporter) num(n *adt.Num, orig []adt.Conjunct) *ast.BasicLit {
Expand Down
266 changes: 0 additions & 266 deletions pkg/path/testdata/join.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -57,272 +57,6 @@ Join: [_]: [
{arg: [#"C:a"#, #"b"#]},
{arg: [#"\\host\share"#, #"foo"#]},
]
-- out/path-v3 --
joinSingle: "a/b"
Join: {
unix: [{
arg: ["a", "b"]
out: "a/b"
}, {
arg: ["a/b", "c/d"]
out: "a/b/c/d"
}, {
arg: ["/"]
out: "/"
}, {
arg: ["a"]
out: "a"
}, {
arg: ["a", "b"]
out: "a/b"
}, {
arg: ["a", ""]
out: "a"
}, {
arg: ["", "b"]
out: "b"
}, {
arg: ["/", "a"]
out: "/a"
}, {
arg: ["/", "a/b"]
out: "/a/b"
}, {
arg: ["/", ""]
out: "/"
}, {
arg: ["//", "a"]
out: "/a"
}, {
arg: ["directory", "file"]
out: "directory/file"
}, {
arg: ["C:\\Windows\\", "System32"]
out: "C:\\Windows\\/System32"
}, {
arg: ["C:\\Windows\\", ""]
out: "C:\\Windows\\"
}, {
arg: ["C:\\", "Windows"]
out: "C:\\/Windows"
}, {
arg: ["C:", "a\\b"]
out: "C:/a\\b"
}, {
arg: ["C:", "a", "b"]
out: "C:/a/b"
}, {
arg: ["C:", "", "", "b"]
out: "C:/b"
}, {
arg: ["C:", ""]
out: "C:"
}, {
arg: ["C:", "", ""]
out: "C:"
}, {
arg: ["C:.", "a"]
out: "C:./a"
}, {
arg: ["C:a", "b"]
out: "C:a/b"
}, {
arg: ["\\\\host\\share", "foo"]
out: "\\\\host\\share/foo"
}]
windows: [{
arg: ["a", "b"]
out: "a\\b"
}, {
arg: ["a/b", "c/d"]
out: "a\\b\\c\\d"
}, {
arg: ["/"]
out: "\\"
}, {
arg: ["a"]
out: "a"
}, {
arg: ["a", "b"]
out: "a\\b"
}, {
arg: ["a", ""]
out: "a"
}, {
arg: ["", "b"]
out: "b"
}, {
arg: ["/", "a"]
out: "\\a"
}, {
arg: ["/", "a/b"]
out: "\\a\\b"
}, {
arg: ["/", ""]
out: "\\"
}, {
arg: ["//", "a"]
out: "\\a"
}, {
arg: ["directory", "file"]
out: "directory\\file"
}, {
arg: ["C:\\Windows\\", "System32"]
out: "C:\\Windows\\System32"
}, {
arg: ["C:\\Windows\\", ""]
out: "C:\\Windows"
}, {
arg: ["C:\\", "Windows"]
out: "C:\\Windows"
}, {
arg: ["C:", "a\\b"]
out: "C:a\\b"
}, {
arg: ["C:", "a", "b"]
out: "C:a\\b"
}, {
arg: ["C:", "", "", "b"]
out: "C:b"
}, {
arg: ["C:", ""]
out: "C:."
}, {
arg: ["C:", "", ""]
out: "C:."
}, {
arg: ["C:.", "a"]
out: "C:a"
}, {
arg: ["C:a", "b"]
out: "C:a\\b"
}, {
arg: ["\\\\host\\share", "foo"]
out: "\\\\host\\share\\foo"
}]
}
-- diff/-out/path-v3<==>+out/path --
diff old new
--- old
+++ new
@@ -37,37 +37,37 @@
arg: ["directory", "file"]
out: "directory/file"
}, {
- arg: [#"C:\Windows\"#, #"System32"#]
+ arg: ["C:\\Windows\\", "System32"]
out: "C:\\Windows\\/System32"
}, {
- arg: [#"C:\Windows\"#, #""#]
+ arg: ["C:\\Windows\\", ""]
out: "C:\\Windows\\"
}, {
- arg: [#"C:\"#, #"Windows"#]
+ arg: ["C:\\", "Windows"]
out: "C:\\/Windows"
}, {
- arg: [#"C:"#, #"a\b"#]
+ arg: ["C:", "a\\b"]
out: "C:/a\\b"
}, {
- arg: [#"C:"#, #"a"#, #"b"#]
+ arg: ["C:", "a", "b"]
out: "C:/a/b"
}, {
- arg: [#"C:"#, #""#, #""#, #"b"#]
+ arg: ["C:", "", "", "b"]
out: "C:/b"
}, {
- arg: [#"C:"#, #""#]
- out: "C:"
- }, {
- arg: [#"C:"#, #""#, #""#]
- out: "C:"
- }, {
- arg: [#"C:."#, #"a"#]
+ arg: ["C:", ""]
+ out: "C:"
+ }, {
+ arg: ["C:", "", ""]
+ out: "C:"
+ }, {
+ arg: ["C:.", "a"]
out: "C:./a"
}, {
- arg: [#"C:a"#, #"b"#]
+ arg: ["C:a", "b"]
out: "C:a/b"
}, {
- arg: [#"\\host\share"#, #"foo"#]
+ arg: ["\\\\host\\share", "foo"]
out: "\\\\host\\share/foo"
}]
windows: [{
@@ -107,37 +107,37 @@
arg: ["directory", "file"]
out: "directory\\file"
}, {
- arg: [#"C:\Windows\"#, #"System32"#]
+ arg: ["C:\\Windows\\", "System32"]
out: "C:\\Windows\\System32"
}, {
- arg: [#"C:\Windows\"#, #""#]
- out: "C:\\Windows"
- }, {
- arg: [#"C:\"#, #"Windows"#]
- out: "C:\\Windows"
- }, {
- arg: [#"C:"#, #"a\b"#]
- out: "C:a\\b"
- }, {
- arg: [#"C:"#, #"a"#, #"b"#]
- out: "C:a\\b"
- }, {
- arg: [#"C:"#, #""#, #""#, #"b"#]
+ arg: ["C:\\Windows\\", ""]
+ out: "C:\\Windows"
+ }, {
+ arg: ["C:\\", "Windows"]
+ out: "C:\\Windows"
+ }, {
+ arg: ["C:", "a\\b"]
+ out: "C:a\\b"
+ }, {
+ arg: ["C:", "a", "b"]
+ out: "C:a\\b"
+ }, {
+ arg: ["C:", "", "", "b"]
out: "C:b"
}, {
- arg: [#"C:"#, #""#]
- out: "C:."
- }, {
- arg: [#"C:"#, #""#, #""#]
- out: "C:."
- }, {
- arg: [#"C:."#, #"a"#]
+ arg: ["C:", ""]
+ out: "C:."
+ }, {
+ arg: ["C:", "", ""]
+ out: "C:."
+ }, {
+ arg: ["C:.", "a"]
out: "C:a"
}, {
- arg: [#"C:a"#, #"b"#]
- out: "C:a\\b"
- }, {
- arg: [#"\\host\share"#, #"foo"#]
+ arg: ["C:a", "b"]
+ out: "C:a\\b"
+ }, {
+ arg: ["\\\\host\\share", "foo"]
out: "\\\\host\\share\\foo"
}]
}
-- diff/todo/p2 --
Differing string representation of semantically identical strings.
-- out/path --
joinSingle: "a/b"
Join: {
Expand Down

0 comments on commit e9c005d

Please sign in to comment.