diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e3266fa --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Patrick Dewey + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/__snapshots__/test_map.snap b/__snapshots__/test_map.snap deleted file mode 100644 index 462fd96..0000000 --- a/__snapshots__/test_map.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -version: 0.1.0 -test_name: TestMap ---- -map[string]interface {}{"foo":"bar"} \ No newline at end of file diff --git a/__snapshots__/test_map.snap.new b/__snapshots__/test_map.snap.new new file mode 100644 index 0000000..11d67d0 --- /dev/null +++ b/__snapshots__/test_map.snap.new @@ -0,0 +1,7 @@ +--- +version: 0.1.0 +test_name: TestMap +--- +map[string]interface{}{ + string("foo"): string("bar"), +} diff --git a/__snapshots__/test_snap_custom_type.snap b/__snapshots__/test_snap_custom_type.snap deleted file mode 100644 index 5eb19cd..0000000 --- a/__snapshots__/test_snap_custom_type.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -version: 0.1.0 -test_name: TestSnapCustomType ---- -CustomStruct{Name: Alice, Age: } \ No newline at end of file diff --git a/__snapshots__/test_snap_custom_type.snap.new b/__snapshots__/test_snap_custom_type.snap.new new file mode 100644 index 0000000..33070e2 --- /dev/null +++ b/__snapshots__/test_snap_custom_type.snap.new @@ -0,0 +1,8 @@ +--- +version: 0.1.0 +test_name: TestSnapCustomType +--- +freeze_test.CustomStruct{ + Name: string("Alice"), + Age: int(30), +} diff --git a/__snapshots__/test_snap_multiple.snap b/__snapshots__/test_snap_multiple.snap deleted file mode 100644 index 3e6866c..0000000 --- a/__snapshots__/test_snap_multiple.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -version: 0.1.0 -test_name: TestSnapMultiple ---- -value1 -value2 -42 -foo -bar -baz -wibble -wobble -tock \ No newline at end of file diff --git a/__snapshots__/test_snap_multiple.snap.new b/__snapshots__/test_snap_multiple.snap.new new file mode 100644 index 0000000..ffe6ee5 --- /dev/null +++ b/__snapshots__/test_snap_multiple.snap.new @@ -0,0 +1,21 @@ +--- +version: 0.1.0 +test_name: TestSnapMultiple +--- +string("value1") + +string("value2") + +int(42) + +string("foo") + +string("bar") + +string("baz") + +string("wibble") + +string("wobble") + +string("tock") diff --git a/__snapshots__/test_snap_string.snap b/__snapshots__/test_snap_string.snap.new similarity index 100% rename from __snapshots__/test_snap_string.snap rename to __snapshots__/test_snap_string.snap.new diff --git a/freeze.go b/freeze.go index 5de6532..1e4c10b 100644 --- a/freeze.go +++ b/freeze.go @@ -2,8 +2,8 @@ package freeze import ( "fmt" - "reflect" + "github.com/kortschak/utter" "github.com/ptdewey/freeze/internal/diff" "github.com/ptdewey/freeze/internal/files" "github.com/ptdewey/freeze/internal/pretty" @@ -106,22 +106,23 @@ func formatValue(v any) string { return "" } - if formattable, ok := v.(interface{ Format() string }); ok { - return formattable.Format() - } - - if stringer, ok := v.(interface{ String() string }); ok { - return stringer.String() - } - - val := reflect.ValueOf(v) - switch val.Kind() { - case reflect.String: - return v.(string) - case reflect.Struct, reflect.Slice, reflect.Array, reflect.Map: - // TODO: make this better probably (utter?) - return fmt.Sprintf("%#v", v) - default: - return fmt.Sprint(v) - } + // if formattable, ok := v.(interface{ Format() string }); ok { + // return formattable.Format() + // } + // + // if stringer, ok := v.(interface{ String() string }); ok { + // return stringer.String() + // } + // + // val := reflect.ValueOf(v) + // switch val.Kind() { + // case reflect.String: + // return v.(string) + // case reflect.Struct, reflect.Slice, reflect.Array, reflect.Map: + // // TODO: make this better probably (utter?) + // return fmt.Sprintf("%#v", v) + // default: + // return fmt.Sprint(v) + // } + return utter.Sdump(v) } diff --git a/go.mod b/go.mod index fa38ab3..ea2f607 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/ptdewey/freeze go 1.25.2 + +require github.com/kortschak/utter v1.7.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..6e2249a --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/kortschak/utter v1.7.0 h1:6NKMynvGUyqfeMTawfah4zyInlrgwzjkDAHrT+skx/w= +github.com/kortschak/utter v1.7.0/go.mod h1:vSmSjbyrlKjjsL71193LmzBOKgwePk9DH6uFaWHIInc= diff --git a/justfile b/justfile index f8a1416..9d15e01 100644 --- a/justfile +++ b/justfile @@ -5,6 +5,8 @@ clean-test: test: @go test ./... -cover -coverprofile=cover.out +run: + @go run cmd/freeze/main.go clean: @rm -rf ./__snapshots__ diff --git a/review.go b/review.go index 6bfa69d..73b46be 100644 --- a/review.go +++ b/review.go @@ -20,7 +20,6 @@ const ( AcceptAllChoice RejectAllChoice SkipAllChoice - // ToggleDiff Quit ) @@ -48,7 +47,7 @@ func Review() error { return nil } - fmt.Println(pretty.Header("🐦 Freeze - Snapshot Review")) + fmt.Println(pretty.Header("Review Snapshots")) fmt.Printf("Found %d new snapshot(s) to review\n\n", len(snapshots)) return reviewLoop(snapshots) @@ -119,15 +118,6 @@ func reviewLoop(snapshots []string) error { case SkipAllChoice: fmt.Printf(pretty.Warning("⊘ Skipped %d snapshot(s)\n"), len(snapshots)-i) return nil - // case ToggleDiff: - // showDiff = !showDiff - // if acceptErr == nil { - // diffLines := computeDiffLines(accepted, newSnap) - // fmt.Println(pretty.DiffSnapshotBox(accepted, newSnap, diffLines)) - // } else { - // fmt.Println(pretty.NewSnapshotBox(newSnap)) - // } - // continue case Quit: fmt.Println("\nReview interrupted") return nil @@ -163,8 +153,6 @@ func askChoice(reader *bufio.Reader, current, total int) (ReviewChoice, error) { return RejectAllChoice, nil case "S", "Skip All": return SkipAllChoice, nil - // case "d", "diff": - // return ToggleDiff, nil case "q", "quit": return Quit, nil default: