File: README.md

package info (click to toggle)
golang-github-likexian-gokit 0.25.9-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 864 kB
  • sloc: makefile: 5
file content (96 lines) | stat: -rw-r--r-- 1,603 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# GoKit - assert

Assert kits for Golang development.

## Installation

    go get -u github.com/likexian/gokit

## Importing

    import (
        "github.com/likexian/gokit/assert"
    )

## Documentation

Visit the docs on [GoDoc](https://godoc.org/github.com/likexian/gokit/assert)

## Example

### assert panic

```go
func willItPanic() {
    panic("failed")
}
assert.Panic(t, willItPanic)
```

### assert err is nil

```go
fp, err := os.Open("/data/dev/gokit/LICENSE")
assert.Nil(t, err)
```

### assert equal

```go
x := map[string]int{"a": 1, "b": 2}
y := map[string]int{"a": 1, "b": 2}
assert.Equal(t, x, y, "x shall equal to y")
```

### check string in array

```go
ok := assert.IsContains([]string{"a", "b", "c"}, "b")
if ok {
    fmt.Println("value in array")
} else {
    fmt.Println("value not in array")
}
```

### check string in interface array

```go
ok := assert.IsContains([]interface{}{0, "1", 2}, "1")
if ok {
    fmt.Println("value in array")
} else {
    fmt.Println("value not in array")
}
```

### check object in struct array

```go
ok := assert.IsContains([]A{A{0, 1}, A{1, 2}, A{1, 3}}, A{1, 2})
if ok {
    fmt.Println("value in array")
} else {
    fmt.Println("value not in array")
}
```

### a := c ? x : y

```go
a := 1
// b := a == 1 ? true : false
b := assert.If(a == 1, true, false)
```

## License

Copyright 2012-2022 [Li Kexian](https://www.likexian.com/)

Licensed under the Apache License 2.0

## Donation

If this project is helpful, please share it with friends.

If you want to thank me, you can [give me a cup of coffee](https://www.likexian.com/donate/).