mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package optional_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hanzoai/git/modules/optional"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestOption(t *testing.T) {
|
|
var uninitialized optional.Option[int]
|
|
assert.False(t, uninitialized.Has())
|
|
assert.Equal(t, int(0), uninitialized.Value())
|
|
assert.Equal(t, int(1), uninitialized.ValueOrDefault(1))
|
|
|
|
none := optional.None[int]()
|
|
assert.False(t, none.Has())
|
|
assert.Equal(t, int(0), none.Value())
|
|
assert.Equal(t, int(1), none.ValueOrDefault(1))
|
|
|
|
some := optional.Some(1)
|
|
assert.True(t, some.Has())
|
|
assert.Equal(t, int(1), some.Value())
|
|
assert.Equal(t, int(1), some.ValueOrDefault(2))
|
|
|
|
noneBool := optional.None[bool]()
|
|
assert.False(t, noneBool.Has())
|
|
assert.False(t, noneBool.Value())
|
|
assert.True(t, noneBool.ValueOrDefault(true))
|
|
|
|
someBool := optional.Some(true)
|
|
assert.True(t, someBool.Has())
|
|
assert.True(t, someBool.Value())
|
|
assert.True(t, someBool.ValueOrDefault(false))
|
|
|
|
var ptr *int
|
|
assert.False(t, optional.FromPtr(ptr).Has())
|
|
|
|
int1 := 1
|
|
opt1 := optional.FromPtr(&int1)
|
|
assert.True(t, opt1.Has())
|
|
assert.Equal(t, int(1), opt1.Value())
|
|
|
|
assert.False(t, optional.FromNonDefault("").Has())
|
|
|
|
opt2 := optional.FromNonDefault("test")
|
|
assert.True(t, opt2.Has())
|
|
assert.Equal(t, "test", opt2.Value())
|
|
|
|
assert.False(t, optional.FromNonDefault(0).Has())
|
|
|
|
opt3 := optional.FromNonDefault(1)
|
|
assert.True(t, opt3.Has())
|
|
assert.Equal(t, int(1), opt3.Value())
|
|
|
|
opt4 := optional.FromMapLookup(map[string]int{"a": 1}, "a")
|
|
assert.True(t, opt4.Has())
|
|
assert.Equal(t, 1, opt4.Value())
|
|
opt4 = optional.FromMapLookup(map[string]int{"a": 1}, "b")
|
|
assert.False(t, opt4.Has())
|
|
}
|
|
|
|
func Test_ParseBool(t *testing.T) {
|
|
assert.Equal(t, optional.None[bool](), optional.ParseBool(""))
|
|
assert.Equal(t, optional.None[bool](), optional.ParseBool("x"))
|
|
|
|
assert.Equal(t, optional.Some(false), optional.ParseBool("0"))
|
|
assert.Equal(t, optional.Some(false), optional.ParseBool("f"))
|
|
assert.Equal(t, optional.Some(false), optional.ParseBool("False"))
|
|
|
|
assert.Equal(t, optional.Some(true), optional.ParseBool("1"))
|
|
assert.Equal(t, optional.Some(true), optional.ParseBool("t"))
|
|
assert.Equal(t, optional.Some(true), optional.ParseBool("True"))
|
|
}
|