diff options
| author | 2026-06-07 11:23:14 +0000 | |
|---|---|---|
| committer | 2026-06-07 11:23:14 +0000 | |
| commit | c277d77899682c05a50cbdaffec09f250669d943 (patch) | |
| tree | 6c7af55e12fb9bbda77f84da189e0785272efec0 /object | |
| parent | object/tree/mode: Roundtrip tests (diff) | |
| signature | No signature | |
object/tree/mode: Other tests
Diffstat (limited to 'object')
| -rw-r--r-- | object/tree/mode/mode_test.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/object/tree/mode/mode_test.go b/object/tree/mode/mode_test.go new file mode 100644 index 00000000..0e2cc2aa --- /dev/null +++ b/object/tree/mode/mode_test.go @@ -0,0 +1,83 @@ +package mode_test + +import ( + "testing" + + "lindenii.org/go/furgit/object/tree/mode" + "lindenii.org/go/furgit/object/typ" +) + +func TestObjectType(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + mode mode.Mode + want typ.Type + }{ + {mode: mode.Directory, want: typ.TypeTree}, + {mode: mode.Regular, want: typ.TypeBlob}, + {mode: mode.Executable, want: typ.TypeBlob}, + {mode: mode.Symlink, want: typ.TypeBlob}, + {mode: mode.Gitlink, want: typ.TypeCommit}, + {mode: mode.Mode(0), want: typ.TypeUnknown}, + } { + if got := tc.mode.ObjectType(); got != tc.want { + t.Fatalf("Mode(%o).ObjectType() = %v, want %v", tc.mode, got, tc.want) + } + } +} + +func TestPredicates(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + mode mode.Mode + valid bool + isBlobLike bool + isRegularFile bool + }{ + {mode: mode.Directory, valid: true, isBlobLike: false, isRegularFile: false}, + {mode: mode.Regular, valid: true, isBlobLike: true, isRegularFile: true}, + {mode: mode.Executable, valid: true, isBlobLike: true, isRegularFile: true}, + {mode: mode.Symlink, valid: true, isBlobLike: true, isRegularFile: false}, + {mode: mode.Gitlink, valid: true, isBlobLike: false, isRegularFile: false}, + {mode: mode.Mode(0), valid: false, isBlobLike: false, isRegularFile: false}, + {mode: mode.Mode(0o100640), valid: false, isBlobLike: false, isRegularFile: false}, + } { + if got := tc.mode.IsValid(); got != tc.valid { + t.Fatalf("Mode(%o).IsValid() = %v, want %v", tc.mode, got, tc.valid) + } + + if got := tc.mode.IsBlobLike(); got != tc.isBlobLike { + t.Fatalf("Mode(%o).IsBlobLike() = %v, want %v", tc.mode, got, tc.isBlobLike) + } + + if got := tc.mode.IsRegularFile(); got != tc.isRegularFile { + t.Fatalf("Mode(%o).IsRegularFile() = %v, want %v", tc.mode, got, tc.isRegularFile) + } + } +} + +func TestHasSameType(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + a mode.Mode + b mode.Mode + want bool + }{ + {a: mode.Regular, b: mode.Regular, want: true}, + {a: mode.Regular, b: mode.Executable, want: true}, + {a: mode.Executable, b: mode.Regular, want: true}, + {a: mode.Regular, b: mode.Symlink, want: false}, + {a: mode.Directory, b: mode.Directory, want: true}, + {a: mode.Directory, b: mode.Regular, want: false}, + {a: mode.Symlink, b: mode.Symlink, want: true}, + {a: mode.Gitlink, b: mode.Gitlink, want: true}, + {a: mode.Gitlink, b: mode.Directory, want: false}, + } { + if got := tc.a.HasSameType(tc.b); got != tc.want { + t.Fatalf("Mode(%o).HasSameType(%o) = %v, want %v", tc.a, tc.b, got, tc.want) + } + } +} |
