
-- in.cue --
// foobar defines at least foo.
package foobar

// A Foo fooses stuff.
Foo: {
	// field1 is an int.
	field1: int

	field2: int

	// duplicate field comment
	dup3: int
}

// foos are instances of Foo.
foos: [string]: Foo

// My first little foo.
foos: MyFoo: {
	// local field comment.
	field1: 0

	// Dangling comment.

	// other field comment.
	field2: 1

	// duplicate field comment
	dup3: int
}

bar: {
	// comment from bar on field 1
	field1: int
	// comment from bar on field 2
	field2: int // don't include this
}

baz: bar & {
	// comment from baz on field 1
	field1: int
	field2: int
}

sub: {
	// comment on comprehension
	if true {
		// comment inside of if comprehension
		field1: int
	}

	// comprehension with nesting.
	for x in [1]
	// nested let
	let y = x
	// nested for
	for z in [y]

	// nested if
	if z == 1 {
		innerField: y
	}

}
-- out.txt --
-- out/doc-v3 --
[]
- foobar defines at least foo.

[Foo]
- A Foo fooses stuff.

[Foo field1]
- field1 is an int.

[Foo field2]
[Foo dup3]
- duplicate field comment

[foos]
- foos are instances of Foo.

[foos MyFoo]
- My first little foo.

[foos MyFoo field1]
- local field comment.

- field1 is an int.

[foos MyFoo field2]
- other field comment.

[foos MyFoo dup3]
- duplicate field comment

[bar]
[bar field1]
- comment from bar on field 1

[bar field2]
- comment from bar on field 2

[baz]
[baz field1]
- comment from baz on field 1

- comment from bar on field 1

[baz field2]
- comment from bar on field 2

[sub]
[sub field1]
- comment inside of if comprehension

[sub innerField]
-- diff/-out/doc-v3<==>+out/doc --
diff old new
--- old
+++ new
@@ -37,10 +37,10 @@
 
 [baz]
 [baz field1]
-- comment from bar on field 1
-
 - comment from baz on field 1
 
+- comment from bar on field 1
+
 [baz field2]
 - comment from bar on field 2
 
-- diff/out/explanation --
Reordering.
-- out/doc --
[]
- foobar defines at least foo.

[Foo]
- A Foo fooses stuff.

[Foo field1]
- field1 is an int.

[Foo field2]
[Foo dup3]
- duplicate field comment

[foos]
- foos are instances of Foo.

[foos MyFoo]
- My first little foo.

[foos MyFoo field1]
- local field comment.

- field1 is an int.

[foos MyFoo field2]
- other field comment.

[foos MyFoo dup3]
- duplicate field comment

[bar]
[bar field1]
- comment from bar on field 1

[bar field2]
- comment from bar on field 2

[baz]
[baz field1]
- comment from bar on field 1

- comment from baz on field 1

[baz field2]
- comment from bar on field 2

[sub]
[sub field1]
- comment inside of if comprehension

[sub innerField]
-- out/definition --
// foobar defines at least foo.
package foobar

// A Foo fooses stuff.
Foo: {
	// field1 is an int.
	field1: int
	field2: int

	// duplicate field comment
	dup3: int
}

// foos are instances of Foo.
foos: {
	{
		[string]: Foo
	}
	MyFoo: {
		// local field comment.
		field1: 0

		// other field comment.
		field2: 1

		// duplicate field comment
		dup3: int
	}
}
bar: {
	// comment from bar on field 1
	field1: int
	// comment from bar on field 2
	field2: int
}
baz: bar & {
	// comment from baz on field 1
	field1: int
	field2: int
}
sub: {
	// comment on comprehension
	if true {
		// comment inside of if comprehension
		field1: int
	}

	// comprehension with nesting.
	for x in [1]
	// nested let
	let y = x
	// nested for
	for z in [y]

	// nested if
	if z == 1 {
		innerField: y
	}
}
-- out/value-v3 --
== Simplified
{
	// A Foo fooses stuff.
	Foo: {
		// field1 is an int.
		field1: int
		field2: int

		// duplicate field comment
		dup3: int
	}

	// foos are instances of Foo.
	foos: {
		// My first little foo.
		MyFoo: {
			// local field comment.

			// field1 is an int.
			field1: 0

			// other field comment.
			field2: 1

			// duplicate field comment
			dup3: int
		}
	}
	bar: {
		// comment from bar on field 1
		field1: int
		// comment from bar on field 2
		field2: int
	}
	baz: {
		// comment from baz on field 1

		// comment from bar on field 1
		field1: int
		// comment from bar on field 2
		field2: int
	}
	sub: {
		// comment inside of if comprehension
		field1:     int
		innerField: 1
	}
}
== Raw
{
	// A Foo fooses stuff.
	Foo: {
		// field1 is an int.
		field1: int
		field2: int

		// duplicate field comment
		dup3: int
	}

	// foos are instances of Foo.
	foos: {
		// My first little foo.
		MyFoo: {
			// local field comment.

			// field1 is an int.
			field1: 0

			// other field comment.
			field2: 1

			// duplicate field comment
			dup3: int
		}
	}
	bar: {
		// comment from bar on field 1
		field1: int
		// comment from bar on field 2
		field2: int
	}
	baz: {
		// comment from baz on field 1

		// comment from bar on field 1
		field1: int
		// comment from bar on field 2
		field2: int
	}
	sub: {
		// comment inside of if comprehension
		field1:     int
		innerField: 1
	}
}
== Final
{
	Foo: {
		field1: int
		field2: int
		dup3:   int
	}
	foos: {
		MyFoo: {
			field1: 0
			field2: 1
			dup3:   int
		}
	}
	bar: {
		field1: int
		field2: int
	}
	baz: {
		field1: int
		field2: int
	}
	sub: {
		field1:     int
		innerField: 1
	}
}
== All
{
	// A Foo fooses stuff.
	Foo: {
		// field1 is an int.
		field1: int
		field2: int

		// duplicate field comment
		dup3: int
	}

	// foos are instances of Foo.
	foos: {
		// My first little foo.
		MyFoo: {
			// local field comment.

			// field1 is an int.
			field1: 0

			// other field comment.
			field2: 1

			// duplicate field comment
			dup3: int
		}
	}
	bar: {
		// comment from bar on field 1
		field1: int
		// comment from bar on field 2
		field2: int
	}
	baz: {
		// comment from baz on field 1

		// comment from bar on field 1
		field1: int
		// comment from bar on field 2
		field2: int
	}
	sub: {
		// comment inside of if comprehension
		field1:     int
		innerField: 1
	}
}
== Eval
{
	Foo: {
		field1: int
		field2: int
		dup3:   int
	}
	foos: {
		MyFoo: {
			field1: 0
			field2: 1
			dup3:   int
		}
	}
	bar: {
		field1: int
		field2: int
	}
	baz: {
		field1: int
		field2: int
	}
	sub: {
		field1:     int
		innerField: 1
	}
}
-- diff/-out/value-v3<==>+out/value --
diff old new
--- old
+++ new
@@ -33,9 +33,9 @@
 		field2: int
 	}
 	baz: {
-		// comment from bar on field 1
-
-		// comment from baz on field 1
+		// comment from baz on field 1
+
+		// comment from bar on field 1
 		field1: int
 		// comment from bar on field 2
 		field2: int
@@ -81,9 +81,9 @@
 		field2: int
 	}
 	baz: {
-		// comment from bar on field 1
-
-		// comment from baz on field 1
+		// comment from baz on field 1
+
+		// comment from bar on field 1
 		field1: int
 		// comment from bar on field 2
 		field2: int
@@ -156,9 +156,9 @@
 		field2: int
 	}
 	baz: {
-		// comment from bar on field 1
-
-		// comment from baz on field 1
+		// comment from baz on field 1
+
+		// comment from bar on field 1
 		field1: int
 		// comment from bar on field 2
 		field2: int
-- diff/value/explanation --
Reordering.
-- out/value --
== Simplified
{
	// A Foo fooses stuff.
	Foo: {
		// field1 is an int.
		field1: int
		field2: int

		// duplicate field comment
		dup3: int
	}

	// foos are instances of Foo.
	foos: {
		// My first little foo.
		MyFoo: {
			// local field comment.

			// field1 is an int.
			field1: 0

			// other field comment.
			field2: 1

			// duplicate field comment
			dup3: int
		}
	}
	bar: {
		// comment from bar on field 1
		field1: int
		// comment from bar on field 2
		field2: int
	}
	baz: {
		// comment from bar on field 1

		// comment from baz on field 1
		field1: int
		// comment from bar on field 2
		field2: int
	}
	sub: {
		// comment inside of if comprehension
		field1:     int
		innerField: 1
	}
}
== Raw
{
	// A Foo fooses stuff.
	Foo: {
		// field1 is an int.
		field1: int
		field2: int

		// duplicate field comment
		dup3: int
	}

	// foos are instances of Foo.
	foos: {
		// My first little foo.
		MyFoo: {
			// local field comment.

			// field1 is an int.
			field1: 0

			// other field comment.
			field2: 1

			// duplicate field comment
			dup3: int
		}
	}
	bar: {
		// comment from bar on field 1
		field1: int
		// comment from bar on field 2
		field2: int
	}
	baz: {
		// comment from bar on field 1

		// comment from baz on field 1
		field1: int
		// comment from bar on field 2
		field2: int
	}
	sub: {
		// comment inside of if comprehension
		field1:     int
		innerField: 1
	}
}
== Final
{
	Foo: {
		field1: int
		field2: int
		dup3:   int
	}
	foos: {
		MyFoo: {
			field1: 0
			field2: 1
			dup3:   int
		}
	}
	bar: {
		field1: int
		field2: int
	}
	baz: {
		field1: int
		field2: int
	}
	sub: {
		field1:     int
		innerField: 1
	}
}
== All
{
	// A Foo fooses stuff.
	Foo: {
		// field1 is an int.
		field1: int
		field2: int

		// duplicate field comment
		dup3: int
	}

	// foos are instances of Foo.
	foos: {
		// My first little foo.
		MyFoo: {
			// local field comment.

			// field1 is an int.
			field1: 0

			// other field comment.
			field2: 1

			// duplicate field comment
			dup3: int
		}
	}
	bar: {
		// comment from bar on field 1
		field1: int
		// comment from bar on field 2
		field2: int
	}
	baz: {
		// comment from bar on field 1

		// comment from baz on field 1
		field1: int
		// comment from bar on field 2
		field2: int
	}
	sub: {
		// comment inside of if comprehension
		field1:     int
		innerField: 1
	}
}
== Eval
{
	Foo: {
		field1: int
		field2: int
		dup3:   int
	}
	foos: {
		MyFoo: {
			field1: 0
			field2: 1
			dup3:   int
		}
	}
	bar: {
		field1: int
		field2: int
	}
	baz: {
		field1: int
		field2: int
	}
	sub: {
		field1:     int
		innerField: 1
	}
}
