mirror of
https://github.com/jimeh/undent.git
synced 2026-02-19 11:56:39 +00:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1148580df | ||
|
c3c5f71c7a
|
|||
|
2e276c037b
|
|||
| af31c21ec1 | |||
|
84715b90d0
|
|||
|
3878874bbe
|
|||
| 23c6c4cd7d | |||
|
|
1a0b0aafae | ||
|
bf5d7b709e
|
|||
|
5890256a45
|
|||
| 5e31bd0485 | |||
|
178d9b5bf6
|
|||
| 20ac9c9824 | |||
|
caeba6291d
|
|||
|
044587fb4c
|
|||
| 69ffce4dca | |||
|
a0b74d98db
|
|||
|
cf20ee4e75
|
|||
|
369ec87ddd
|
|||
|
5a4b199462
|
|||
| 86be1bf614 | |||
|
6a2254e918
|
|||
|
98946bf286
|
|||
|
f0855f3a83
|
|||
| c3e2bd98b0 | |||
|
fe6ba9c1c4
|
|||
|
d1c5735041
|
|||
|
5cae4bc420
|
|||
|
4ded03bd72
|
|||
| 68a97519d5 | |||
|
5dbdbbf341
|
|||
|
d79e413e8e
|
|||
| cc372da881 | |||
|
b2057429a1
|
|||
|
24e64f6c39
|
|||
|
30dba69951
|
59
.github/workflows/ci.yml
vendored
59
.github/workflows/ci.yml
vendored
@@ -7,11 +7,14 @@ jobs:
|
|||||||
name: Lint
|
name: Lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: golangci-lint
|
- uses: actions/setup-go@v3
|
||||||
uses: golangci/golangci-lint-action@v2
|
|
||||||
with:
|
with:
|
||||||
version: v1.31
|
go-version: 1.15
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v3
|
||||||
|
with:
|
||||||
|
version: v1.50
|
||||||
env:
|
env:
|
||||||
VERBOSE: "true"
|
VERBOSE: "true"
|
||||||
|
|
||||||
@@ -19,11 +22,11 @@ jobs:
|
|||||||
name: Tidy
|
name: Tidy
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.15
|
go-version: 1.15
|
||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
@@ -35,13 +38,13 @@ jobs:
|
|||||||
benchmark:
|
benchmark:
|
||||||
name: Benchmarks
|
name: Benchmarks
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.ref != 'refs/heads/master'
|
if: github.ref != 'refs/heads/main'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.15
|
go-version: 1.15
|
||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
@@ -67,18 +70,18 @@ jobs:
|
|||||||
name: Coverage
|
name: Coverage
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.15
|
go-version: 1.15
|
||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go-
|
${{ runner.os }}-go-
|
||||||
- name: Publish coverage
|
- name: Publish coverage
|
||||||
uses: paambaati/codeclimate-action@v2.7.4
|
uses: paambaati/codeclimate-action@v3.2.0
|
||||||
env:
|
env:
|
||||||
VERBOSE: "true"
|
VERBOSE: "true"
|
||||||
GOMAXPROCS: 4
|
GOMAXPROCS: 4
|
||||||
@@ -93,11 +96,11 @@ jobs:
|
|||||||
name: Test
|
name: Test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.15
|
go-version: 1.15
|
||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
@@ -111,13 +114,13 @@ jobs:
|
|||||||
benchmark-store:
|
benchmark-store:
|
||||||
name: Store benchmarks
|
name: Store benchmarks
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.ref == 'refs/heads/master'
|
if: github.ref == 'refs/heads/main'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.15
|
go-version: 1.15
|
||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
@@ -134,6 +137,16 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
tool: "go"
|
tool: "go"
|
||||||
output-file-path: output.txt
|
output-file-path: output.txt
|
||||||
github-token: ${{ secrets.GH_PUSH_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
comment-on-alert: true
|
comment-on-alert: true
|
||||||
auto-push: true
|
auto-push: true
|
||||||
|
|
||||||
|
release-please:
|
||||||
|
needs: [lint, tidy, test]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
steps:
|
||||||
|
- uses: google-github-actions/release-please-action@v3
|
||||||
|
id: release-please
|
||||||
|
with:
|
||||||
|
command: manifest
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ linters-settings:
|
|||||||
golint:
|
golint:
|
||||||
min-confidence: 0
|
min-confidence: 0
|
||||||
govet:
|
govet:
|
||||||
check-shadowing: true
|
|
||||||
enable-all: true
|
enable-all: true
|
||||||
|
disable:
|
||||||
|
- fieldalignment
|
||||||
lll:
|
lll:
|
||||||
line-length: 80
|
line-length: 80
|
||||||
tab-width: 4
|
tab-width: 4
|
||||||
@@ -21,10 +22,10 @@ linters:
|
|||||||
disable-all: true
|
disable-all: true
|
||||||
enable:
|
enable:
|
||||||
- bodyclose
|
- bodyclose
|
||||||
- deadcode
|
|
||||||
- depguard
|
- depguard
|
||||||
- dupl
|
- dupl
|
||||||
- errcheck
|
- errcheck
|
||||||
|
- exportloopref
|
||||||
- funlen
|
- funlen
|
||||||
- gochecknoinits
|
- gochecknoinits
|
||||||
- goconst
|
- goconst
|
||||||
@@ -32,7 +33,6 @@ linters:
|
|||||||
- gocyclo
|
- gocyclo
|
||||||
- goerr113
|
- goerr113
|
||||||
- goimports
|
- goimports
|
||||||
- golint
|
|
||||||
- goprintffuncname
|
- goprintffuncname
|
||||||
- gosec
|
- gosec
|
||||||
- gosimple
|
- gosimple
|
||||||
@@ -44,19 +44,15 @@ linters:
|
|||||||
- nlreturn
|
- nlreturn
|
||||||
- noctx
|
- noctx
|
||||||
- nolintlint
|
- nolintlint
|
||||||
- scopelint
|
- revive
|
||||||
- sqlclosecheck
|
- sqlclosecheck
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- structcheck
|
|
||||||
- typecheck
|
- typecheck
|
||||||
- unconvert
|
- unconvert
|
||||||
- unused
|
- unused
|
||||||
- varcheck
|
|
||||||
- whitespace
|
- whitespace
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
include:
|
|
||||||
# - EXC0002 # disable excluding of issues about comments from golint
|
|
||||||
exclude:
|
exclude:
|
||||||
- Using the variable on range scope `tt` in function literal
|
- Using the variable on range scope `tt` in function literal
|
||||||
- Using the variable on range scope `tc` in function literal
|
- Using the variable on range scope `tc` in function literal
|
||||||
|
|||||||
3
.release-please-manifest.json
Normal file
3
.release-please-manifest.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
".": "1.1.2"
|
||||||
|
}
|
||||||
36
CHANGELOG.md
36
CHANGELOG.md
@@ -1,6 +1,40 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
## [1.1.2](https://github.com/jimeh/undent/compare/v1.1.1...v1.1.2) (2024-10-21)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **perf:** minor improvement when no indent is found ([84715b9](https://github.com/jimeh/undent/commit/84715b90d000292e4e4fbe081e00a583acf0dada))
|
||||||
|
|
||||||
|
## [1.1.1](https://github.com/jimeh/undent/compare/v1.1.0...v1.1.1) (2022-12-05)
|
||||||
|
|
||||||
|
|
||||||
|
### Performance Improvements
|
||||||
|
|
||||||
|
* simplify line-feed and minimum indentation loops ([178d9b5](https://github.com/jimeh/undent/commit/178d9b5bf6dd090a406229e862c5da1ba26cbf5d))
|
||||||
|
|
||||||
|
## [1.1.0](https://github.com/jimeh/undent/compare/v1.0.2...v1.1.0) (2021-02-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **performance:** improve core undenting performance by around 20-30x ([6a2254e](https://github.com/jimeh/undent/commit/6a2254e918944e5ead4d5a4d6d1b95b0e971c4b7))
|
||||||
|
* **print** add Print, Printf, Fprint, and Fprintf functions ([5cae4bc](https://github.com/jimeh/undent/commit/5cae4bc420f7bec12efd6071149eac88c37cfd9f))
|
||||||
|
|
||||||
|
### [1.0.2](https://github.com/jimeh/undent/compare/v1.0.1...v1.0.2) (2020-12-14)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **bytes:** change Bytes function to accept string input but return a byte slice ([5dbdbbf](https://github.com/jimeh/undent/commit/5dbdbbf3416b024aac8fca4e218802d6ad49ea74))
|
||||||
|
|
||||||
|
### [1.0.1](https://github.com/jimeh/undent/compare/v1.0.0...v1.0.1) (2020-12-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **whitespace:** remove leading line-break from input ([b205742](https://github.com/jimeh/undent/commit/b2057429a1181724ae50acaed26fe434231362b4))
|
||||||
|
|
||||||
## 1.0.0 (2020-11-26)
|
## 1.0.0 (2020-11-26)
|
||||||
|
|
||||||
|
|||||||
25
Makefile
25
Makefile
@@ -1,3 +1,4 @@
|
|||||||
|
GOMODNAME := $(shell grep 'module' go.mod | sed -e 's/^module //')
|
||||||
SOURCES := $(shell find . -name "*.go" -or -name "go.mod" -or -name "go.sum" \
|
SOURCES := $(shell find . -name "*.go" -or -name "go.mod" -or -name "go.sum" \
|
||||||
-or -name "Makefile")
|
-or -name "Makefile")
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ SHELL ?= /bin/bash
|
|||||||
SHELL := env \
|
SHELL := env \
|
||||||
GO111MODULE=on \
|
GO111MODULE=on \
|
||||||
GOBIN=$(CURDIR)/$(TOOLDIR) \
|
GOBIN=$(CURDIR)/$(TOOLDIR) \
|
||||||
CGO_ENABLED=1 \
|
CGO_ENABLED=0 \
|
||||||
PATH='$(CURDIR)/$(BINDIR):$(CURDIR)/$(TOOLDIR):$(PATH)' \
|
PATH='$(CURDIR)/$(BINDIR):$(CURDIR)/$(TOOLDIR):$(PATH)' \
|
||||||
$(SHELL)
|
$(SHELL)
|
||||||
|
|
||||||
@@ -34,7 +35,6 @@ SHELL := env \
|
|||||||
#
|
#
|
||||||
|
|
||||||
TOOLS += $(TOOLDIR)/gobin
|
TOOLS += $(TOOLDIR)/gobin
|
||||||
gobin: $(TOOLDIR)/gobin
|
|
||||||
$(TOOLDIR)/gobin:
|
$(TOOLDIR)/gobin:
|
||||||
GO111MODULE=off go get -u github.com/myitcv/gobin
|
GO111MODULE=off go get -u github.com/myitcv/gobin
|
||||||
|
|
||||||
@@ -42,16 +42,13 @@ $(TOOLDIR)/gobin:
|
|||||||
define tool # 1: binary-name, 2: go-import-path
|
define tool # 1: binary-name, 2: go-import-path
|
||||||
TOOLS += $(TOOLDIR)/$(1)
|
TOOLS += $(TOOLDIR)/$(1)
|
||||||
|
|
||||||
.PHONY: $(1)
|
|
||||||
$(1): $(TOOLDIR)/$(1)
|
|
||||||
|
|
||||||
$(TOOLDIR)/$(1): $(TOOLDIR)/gobin Makefile
|
$(TOOLDIR)/$(1): $(TOOLDIR)/gobin Makefile
|
||||||
gobin $(V) "$(2)"
|
gobin $(V) "$(2)"
|
||||||
endef
|
endef
|
||||||
|
|
||||||
$(eval $(call tool,godoc,golang.org/x/tools/cmd/godoc))
|
$(eval $(call tool,godoc,golang.org/x/tools/cmd/godoc))
|
||||||
$(eval $(call tool,gofumports,mvdan.cc/gofumpt/gofumports))
|
$(eval $(call tool,gofumports,mvdan.cc/gofumpt/gofumports))
|
||||||
$(eval $(call tool,golangci-lint,github.com/golangci/golangci-lint/cmd/golangci-lint@v1.31))
|
$(eval $(call tool,golangci-lint,github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50))
|
||||||
|
|
||||||
.PHONY: tools
|
.PHONY: tools
|
||||||
tools: $(TOOLS)
|
tools: $(TOOLS)
|
||||||
@@ -75,25 +72,18 @@ clean-golden:
|
|||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
go test $(V) -count=1 -race $(TESTARGS) $(TEST)
|
CGO_ENABLED=1 go test $(V) -count=1 -race $(TESTARGS) $(TEST)
|
||||||
|
|
||||||
.PHONY: test-update-golden
|
|
||||||
test-update-golden:
|
|
||||||
@$(MAKE) test UPDATE_GOLDEN=1
|
|
||||||
|
|
||||||
.PHONY: regen-golden
|
|
||||||
regen-golden: clean-golden test-update-golden
|
|
||||||
|
|
||||||
.PHONY: test-deps
|
.PHONY: test-deps
|
||||||
test-deps:
|
test-deps:
|
||||||
go test all
|
go test all
|
||||||
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint: golangci-lint
|
lint: $(TOOLDIR)/golangci-lint
|
||||||
GOGC=off golangci-lint $(V) run
|
GOGC=off golangci-lint $(V) run
|
||||||
|
|
||||||
.PHONY: format
|
.PHONY: format
|
||||||
format: gofumports
|
format: $(TOOLDIR)/gofumports
|
||||||
gofumports -w .
|
gofumports -w .
|
||||||
|
|
||||||
.SILENT: bench
|
.SILENT: bench
|
||||||
@@ -161,7 +151,8 @@ check-tidy:
|
|||||||
|
|
||||||
# Serve docs
|
# Serve docs
|
||||||
.PHONY: docs
|
.PHONY: docs
|
||||||
docs: godoc
|
docs: $(TOOLDIR)/godoc
|
||||||
|
$(info serving docs on http://127.0.0.1:6060/pkg/$(GOMODNAME)/)
|
||||||
@godoc -http=127.0.0.1:6060
|
@godoc -http=127.0.0.1:6060
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|||||||
45
README.md
45
README.md
@@ -4,35 +4,18 @@
|
|||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<strong>
|
<strong>
|
||||||
Go package which removes leading indentation/white-space from multi-line
|
Go package which removes leading indentation/white-space from strings.
|
||||||
strings and byte slices.
|
|
||||||
</strong>
|
</strong>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://pkg.go.dev/github.com/jimeh/undent">
|
<a href="https://pkg.go.dev/github.com/jimeh/undent"><img src="https://img.shields.io/badge/%E2%80%8B-reference-387b97.svg?logo=go&logoColor=white" alt="Go Reference"></a>
|
||||||
<img src="https://img.shields.io/badge/%E2%80%8B-reference-387b97.svg?logo=go&logoColor=white"
|
<a href="https://github.com/jimeh/undent/releases"><img src="https://img.shields.io/github/v/tag/jimeh/undent?label=release" alt="GitHub tag (latest SemVer)"></a>
|
||||||
alt="Go Reference">
|
<a href="https://github.com/jimeh/undent/actions"><img src="https://img.shields.io/github/actions/workflow/status/jimeh/undent/ci.yml?logo=github" alt="Actions Status"></a>
|
||||||
</a>
|
<a href="https://codeclimate.com/github/jimeh/undent"><img src="https://img.shields.io/codeclimate/coverage/jimeh/undent.svg?logo=code%20climate" alt="Coverage"></a>
|
||||||
<a href="https://github.com/jimeh/undent/releases">
|
<a href="https://github.com/jimeh/undent/issues"><img src="https://img.shields.io/github/issues-raw/jimeh/undent.svg?style=flat&logo=github&logoColor=white" alt="GitHub issues"></a>
|
||||||
<img src="https://img.shields.io/github/v/tag/jimeh/undent?label=release" alt="GitHub tag (latest SemVer)">
|
<a href="https://github.com/jimeh/undent/pulls"><img src="https://img.shields.io/github/issues-pr-raw/jimeh/undent.svg?style=flat&logo=github&logoColor=white" alt="GitHub pull requests"></a>
|
||||||
</a>
|
<a href="https://github.com/jimeh/undent/blob/main/LICENSE"><img src="https://img.shields.io/github/license/jimeh/undent.svg?style=flat" alt="License Status"></a>
|
||||||
<a href="https://github.com/jimeh/undent/actions">
|
|
||||||
<img src="https://img.shields.io/github/workflow/status/jimeh/undent/CI.svg?logo=github" alt="Actions Status">
|
|
||||||
</a>
|
|
||||||
<a href="https://codeclimate.com/github/jimeh/undent">
|
|
||||||
<img src="https://img.shields.io/codeclimate/coverage/jimeh/undent.svg?logo=code%20climate" alt="Coverage">
|
|
||||||
</a>
|
|
||||||
<a href="https://github.com/jimeh/undent/issues">
|
|
||||||
<img src="https://img.shields.io/github/issues-raw/jimeh/undent.svg?style=flat&logo=github&logoColor=white"
|
|
||||||
alt="GitHub issues">
|
|
||||||
</a>
|
|
||||||
<a href="https://github.com/jimeh/undent/pulls">
|
|
||||||
<img src="https://img.shields.io/github/issues-pr-raw/jimeh/undent.svg?style=flat&logo=github&logoColor=white" alt="GitHub pull requests">
|
|
||||||
</a>
|
|
||||||
<a href="https://github.com/jimeh/undent/blob/master/LICENSE">
|
|
||||||
<img src="https://img.shields.io/github/license/jimeh/undent.svg?style=flat" alt="License Status">
|
|
||||||
</a>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
@@ -52,9 +35,15 @@ fmt.Println(s)
|
|||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
Please see the [Go Reference](https://pkg.go.dev/github.com/jimeh/undent) for
|
Please see the
|
||||||
documentation and examples.
|
[Go Reference](https://pkg.go.dev/github.com/jimeh/undent#section-documentation)
|
||||||
|
for documentation and examples.
|
||||||
|
|
||||||
|
## Benchmarks
|
||||||
|
|
||||||
|
Benchmark reports and graphs are available here:
|
||||||
|
https://jimeh.me/undent/dev/bench/
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[MIT](https://github.com/jimeh/undent/blob/master/LICENSE)
|
[MIT](https://github.com/jimeh/undent/blob/main/LICENSE)
|
||||||
|
|||||||
5
go.mod
5
go.mod
@@ -2,4 +2,7 @@ module github.com/jimeh/undent
|
|||||||
|
|
||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
require github.com/stretchr/testify v1.6.1
|
require (
|
||||||
|
github.com/rhysd/go-fakeio v1.0.0
|
||||||
|
github.com/stretchr/testify v1.6.1
|
||||||
|
)
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -2,6 +2,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rhysd/go-fakeio v1.0.0 h1:+TjiKCOs32dONY7DaoVz/VPOdvRkPfBkEyUDIpM8FQY=
|
||||||
|
github.com/rhysd/go-fakeio v1.0.0/go.mod h1:joYxF906trVwp2JLrE4jlN7A0z6wrz8O6o1UjarbFzE=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
|||||||
14
release-please-config.json
Normal file
14
release-please-config.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"release-type": "go",
|
||||||
|
"bump-minor-pre-major": true,
|
||||||
|
"bump-patch-for-minor-pre-major": true,
|
||||||
|
"packages": {
|
||||||
|
".": {
|
||||||
|
"changelog-path": "CHANGELOG.md",
|
||||||
|
"draft": false,
|
||||||
|
"prerelease": false,
|
||||||
|
"extra-files": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
|
||||||
|
}
|
||||||
144
undent.go
144
undent.go
@@ -4,65 +4,86 @@ package undent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"io"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var matcher = regexp.MustCompile(`(?m)^([ \t]*)(?:\S)`)
|
const (
|
||||||
|
tab = 9
|
||||||
|
lf = 10
|
||||||
|
spc = 32
|
||||||
|
)
|
||||||
|
|
||||||
// Bytes removes leading indentation/white-space from given byte slice.
|
// Bytes removes leading indentation/white-space from given string and returns
|
||||||
func Bytes(b []byte) []byte {
|
// it as a byte slice.
|
||||||
matches := matcher.FindAll(b, -1)
|
func Bytes(s string) []byte {
|
||||||
if len(matches) == 0 {
|
if len(s) == 0 {
|
||||||
return b
|
return []byte{}
|
||||||
}
|
}
|
||||||
|
|
||||||
index := 0
|
// find smallest indent relative to each line-feed
|
||||||
length := len(matches[0])
|
min := -1
|
||||||
|
count := 0
|
||||||
|
|
||||||
for i, s := range matches[1:] {
|
lfs := make([]int, 0, strings.Count(s, "\n"))
|
||||||
l := len(s)
|
if s[0] != lf {
|
||||||
if l < length {
|
lfs = append(lfs, -1)
|
||||||
index = i + 1
|
}
|
||||||
length = l
|
|
||||||
|
indent := 0
|
||||||
|
for i := 0; i < len(s); i++ {
|
||||||
|
if s[i] == lf {
|
||||||
|
lfs = append(lfs, i)
|
||||||
|
indent = 0
|
||||||
|
} else if indent < min || min == -1 {
|
||||||
|
switch s[i] {
|
||||||
|
case spc, tab:
|
||||||
|
indent++
|
||||||
|
default:
|
||||||
|
if indent > 0 {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
if indent < min || min == -1 {
|
||||||
|
min = indent
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if length <= 1 {
|
if min == -1 {
|
||||||
return b
|
return []byte(s)
|
||||||
}
|
}
|
||||||
indent := matches[index][0 : length-1]
|
|
||||||
|
|
||||||
return regexp.MustCompile(
|
// extract each line without indentation
|
||||||
`(?m)^`+regexp.QuoteMeta(string(indent)),
|
out := make([]byte, 0, len(s)-(min*count))
|
||||||
).ReplaceAllLiteral(b, []byte{})
|
|
||||||
|
for i := 0; i < len(lfs); i++ {
|
||||||
|
offset := lfs[i] + 1
|
||||||
|
end := len(s)
|
||||||
|
if i+1 < len(lfs) {
|
||||||
|
end = lfs[i+1] + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if offset+min < end {
|
||||||
|
out = append(out, s[offset+min:end]...)
|
||||||
|
} else if offset < end {
|
||||||
|
out = append(out, s[offset:end]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bytesf removes leading indentation/white-space from given format string
|
||||||
|
// before passing format and all additional arguments to fmt.Sprintf, returning
|
||||||
|
// the result as a byte slice.
|
||||||
|
func Bytesf(format string, a ...interface{}) []byte {
|
||||||
|
return []byte(Stringf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// String removes leading indentation/white-space from given string.
|
// String removes leading indentation/white-space from given string.
|
||||||
func String(s string) string {
|
func String(s string) string {
|
||||||
matches := matcher.FindAllString(s, -1)
|
return string(Bytes(s))
|
||||||
if len(matches) == 0 {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
index := 0
|
|
||||||
length := len(matches[0])
|
|
||||||
|
|
||||||
for i, s := range matches[1:] {
|
|
||||||
l := len(s)
|
|
||||||
if l < length {
|
|
||||||
index = i + 1
|
|
||||||
length = l
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if length <= 1 {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
indent := matches[index][0 : length-1]
|
|
||||||
|
|
||||||
return regexp.MustCompile(
|
|
||||||
`(?m)^`+regexp.QuoteMeta(indent),
|
|
||||||
).ReplaceAllLiteralString(s, "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stringf removes leading indentation/white-space from given format string
|
// Stringf removes leading indentation/white-space from given format string
|
||||||
@@ -71,3 +92,38 @@ func String(s string) string {
|
|||||||
func Stringf(format string, a ...interface{}) string {
|
func Stringf(format string, a ...interface{}) string {
|
||||||
return fmt.Sprintf(String(format), a...)
|
return fmt.Sprintf(String(format), a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print will undent any string arguments before passing them to fmt.Print.
|
||||||
|
func Print(a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Print(undentInterfaces(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Printf will undent the given format string before passing it and all
|
||||||
|
// arguments to fmt.Printf.
|
||||||
|
func Printf(format string, a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Printf(String(format), a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fprint will undent any string arguments before passing them to fmt.Fprint.
|
||||||
|
func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Fprint(w, undentInterfaces(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fprintf will undent the given format string before passing it and all
|
||||||
|
// arguments to fmt.Fprintf.
|
||||||
|
func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Fprintf(w, String(format), a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func undentInterfaces(a []interface{}) []interface{} {
|
||||||
|
var r []interface{}
|
||||||
|
|
||||||
|
for _, v := range a {
|
||||||
|
if s, ok := v.(string); ok {
|
||||||
|
v = String(s)
|
||||||
|
}
|
||||||
|
r = append(r, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,21 +1,35 @@
|
|||||||
package undent_test
|
package undent_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jimeh/undent"
|
"github.com/jimeh/undent"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleBytes() {
|
func ExampleBytes() {
|
||||||
b := undent.Bytes([]byte(`
|
b := undent.Bytes(`
|
||||||
{
|
{
|
||||||
"hello": "world"
|
"hello": "world"
|
||||||
}`,
|
}`,
|
||||||
))
|
)
|
||||||
|
|
||||||
fmt.Println(string(b))
|
fmt.Println(string(b))
|
||||||
// Output:
|
// Output:
|
||||||
//
|
// {
|
||||||
|
// "hello": "world"
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleBytesf() {
|
||||||
|
s := undent.Bytesf(`
|
||||||
|
{
|
||||||
|
"hello": "%s"
|
||||||
|
}`,
|
||||||
|
"world",
|
||||||
|
)
|
||||||
|
fmt.Println(string(s))
|
||||||
|
// Output:
|
||||||
// {
|
// {
|
||||||
// "hello": "world"
|
// "hello": "world"
|
||||||
// }
|
// }
|
||||||
@@ -29,7 +43,6 @@ func ExampleString() {
|
|||||||
)
|
)
|
||||||
fmt.Println(s)
|
fmt.Println(s)
|
||||||
// Output:
|
// Output:
|
||||||
//
|
|
||||||
// {
|
// {
|
||||||
// "hello": "world"
|
// "hello": "world"
|
||||||
// }
|
// }
|
||||||
@@ -44,7 +57,60 @@ func ExampleStringf() {
|
|||||||
)
|
)
|
||||||
fmt.Println(s)
|
fmt.Println(s)
|
||||||
// Output:
|
// Output:
|
||||||
//
|
// {
|
||||||
|
// "hello": "world"
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExamplePrint() {
|
||||||
|
undent.Print(`
|
||||||
|
{
|
||||||
|
"hello": "world"
|
||||||
|
}`,
|
||||||
|
)
|
||||||
|
// Output:
|
||||||
|
// {
|
||||||
|
// "hello": "world"
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExamplePrintf() {
|
||||||
|
undent.Printf(`
|
||||||
|
{
|
||||||
|
"hello": "%s"
|
||||||
|
}`,
|
||||||
|
"world",
|
||||||
|
)
|
||||||
|
// Output:
|
||||||
|
// {
|
||||||
|
// "hello": "world"
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleFprint() {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
undent.Fprint(&buf, `
|
||||||
|
{
|
||||||
|
"hello": "world"
|
||||||
|
}`,
|
||||||
|
)
|
||||||
|
fmt.Println(buf.String())
|
||||||
|
// Output:
|
||||||
|
// {
|
||||||
|
// "hello": "world"
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleFprintf() {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
undent.Fprintf(&buf, `
|
||||||
|
{
|
||||||
|
"hello": "%s"
|
||||||
|
}`,
|
||||||
|
"world",
|
||||||
|
)
|
||||||
|
fmt.Println(buf.String())
|
||||||
|
// Output:
|
||||||
// {
|
// {
|
||||||
// "hello": "world"
|
// "hello": "world"
|
||||||
// }
|
// }
|
||||||
|
|||||||
462
undent_test.go
462
undent_test.go
@@ -1,9 +1,12 @@
|
|||||||
package undent
|
package undent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rhysd/go-fakeio"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var stringTestCases = []struct {
|
var stringTestCases = []struct {
|
||||||
@@ -35,8 +38,7 @@ var stringTestCases = []struct {
|
|||||||
"bar"
|
"bar"
|
||||||
]
|
]
|
||||||
}`,
|
}`,
|
||||||
want: `
|
want: `{
|
||||||
{
|
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
"bar"
|
"bar"
|
||||||
@@ -46,6 +48,39 @@ var stringTestCases = []struct {
|
|||||||
{
|
{
|
||||||
name: "multi-line space indented",
|
name: "multi-line space indented",
|
||||||
s: `
|
s: `
|
||||||
|
{
|
||||||
|
"hello": "world",
|
||||||
|
"foo": [
|
||||||
|
"bar"
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
want: `{
|
||||||
|
"hello": "world",
|
||||||
|
"foo": [
|
||||||
|
"bar"
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "multi-line space indented without any leading line-breaks",
|
||||||
|
s: ` {
|
||||||
|
"hello": "world",
|
||||||
|
"foo": [
|
||||||
|
"bar"
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
want: `{
|
||||||
|
"hello": "world",
|
||||||
|
"foo": [
|
||||||
|
"bar"
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "multi-line space indented with leading line-breaks",
|
||||||
|
s: `
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
@@ -53,6 +88,7 @@ var stringTestCases = []struct {
|
|||||||
]
|
]
|
||||||
}`,
|
}`,
|
||||||
want: `
|
want: `
|
||||||
|
|
||||||
{
|
{
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
@@ -63,6 +99,39 @@ var stringTestCases = []struct {
|
|||||||
{
|
{
|
||||||
name: "multi-line tab indented",
|
name: "multi-line tab indented",
|
||||||
s: `
|
s: `
|
||||||
|
{
|
||||||
|
"hello": "world",
|
||||||
|
"foo": [
|
||||||
|
"bar"
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
want: `{
|
||||||
|
"hello": "world",
|
||||||
|
"foo": [
|
||||||
|
"bar"
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "multi-line tab indented without any leading line-breaks",
|
||||||
|
s: ` {
|
||||||
|
"hello": "world",
|
||||||
|
"foo": [
|
||||||
|
"bar"
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
want: `{
|
||||||
|
"hello": "world",
|
||||||
|
"foo": [
|
||||||
|
"bar"
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "multi-line tab indented with leading line-breaks",
|
||||||
|
s: `
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
@@ -70,6 +139,7 @@ var stringTestCases = []struct {
|
|||||||
]
|
]
|
||||||
}`,
|
}`,
|
||||||
want: `
|
want: `
|
||||||
|
|
||||||
{
|
{
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
@@ -86,8 +156,7 @@ var stringTestCases = []struct {
|
|||||||
"bar"
|
"bar"
|
||||||
]
|
]
|
||||||
}`,
|
}`,
|
||||||
want: `
|
want: `{
|
||||||
{
|
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
"bar"
|
"bar"
|
||||||
@@ -105,8 +174,7 @@ var stringTestCases = []struct {
|
|||||||
|
|
||||||
]
|
]
|
||||||
}`,
|
}`,
|
||||||
want: `
|
want: `{
|
||||||
{
|
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
|
|
||||||
@@ -126,8 +194,7 @@ var stringTestCases = []struct {
|
|||||||
|
|
||||||
]
|
]
|
||||||
}`,
|
}`,
|
||||||
want: `
|
want: `{
|
||||||
{
|
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
|
|
||||||
@@ -143,8 +210,7 @@ var stringTestCases = []struct {
|
|||||||
world
|
world
|
||||||
foo
|
foo
|
||||||
bar`,
|
bar`,
|
||||||
want: `
|
want: ` hello
|
||||||
hello
|
|
||||||
world
|
world
|
||||||
foo
|
foo
|
||||||
bar`,
|
bar`,
|
||||||
@@ -156,12 +222,113 @@ world
|
|||||||
world
|
world
|
||||||
foo
|
foo
|
||||||
bar`,
|
bar`,
|
||||||
want: `
|
want: ` hello
|
||||||
hello
|
|
||||||
world
|
world
|
||||||
foo
|
foo
|
||||||
bar`,
|
bar`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "long block of text",
|
||||||
|
s: `
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc
|
||||||
|
ornare, tellus vel luctus tristique, ipsum ante varius mauris, non
|
||||||
|
hendrerit tellus urna quis ex. Donec efficitur arcu sed iaculis
|
||||||
|
lobortis. Phasellus facilisis vitae mi quis accumsan. Suspendisse
|
||||||
|
rhoncus viverra odio ultricies rhoncus. Cras laoreet tortor
|
||||||
|
vestibulum pharetra luctus. Vivamus sit amet volutpat elit.
|
||||||
|
Suspendisse feugiat lectus id arcu sollicitudin tincidunt. Duis ut
|
||||||
|
sem auctor orci sodales varius in ac odio. Nullam finibus odio at
|
||||||
|
lacus tristique malesuada.
|
||||||
|
|
||||||
|
Morbi nisl nulla, euismod eu enim in, tincidunt varius turpis. Morbi
|
||||||
|
ullamcorper tortor mi, ut aliquam metus posuere vel. Etiam vel dui
|
||||||
|
at quam placerat sollicitudin. Proin aliquam justo vitae mauris
|
||||||
|
gravida porta. Praesent hendrerit egestas ligula, faucibus tincidunt
|
||||||
|
tortor aliquet at. Ut luctus vehicula arcu eget cursus. Suspendisse
|
||||||
|
eget enim mollis, condimentum lacus eu, viverra nulla. Aenean vel
|
||||||
|
sapien eget enim convallis accumsan. Donec dictum ullamcorper leo
|
||||||
|
placerat sollicitudin. Pellentesque habitant morbi tristique
|
||||||
|
senectus et netus et malesuada fames ac turpis egestas. Vestibulum
|
||||||
|
volutpat mattis est, a feugiat purus feugiat at. Quisque at velit ut
|
||||||
|
mauris convallis sodales a et erat. Mauris condimentum augue sit
|
||||||
|
amet arcu sodales, aliquet ultrices ipsum tempor. Donec scelerisque
|
||||||
|
mi ligula, vel volutpat velit posuere a. Sed faucibus dui pulvinar
|
||||||
|
lorem commodo egestas. In facilisis suscipit lacus non suscipit.
|
||||||
|
|
||||||
|
Nunc dictum est nulla, a rhoncus mi posuere id. Morbi at tempus
|
||||||
|
augue. Quisque ac nibh auctor velit auctor placerat id non eros.
|
||||||
|
Nulla condimentum quam id risus suscipit, ut fermentum mauris
|
||||||
|
lacinia. Vestibulum suscipit rutrum ex, sed vulputate nisi tempus
|
||||||
|
ultricies. Sed id ante pretium, accumsan sapien eget, malesuada
|
||||||
|
quam. Phasellus quis commodo enim. Vivamus in purus ac lorem ornare
|
||||||
|
posuere non eu quam. Sed arcu tortor, gravida quis fringilla nec,
|
||||||
|
ultricies et sem. Pellentesque arcu enim, tempor id nisl at, rhoncus
|
||||||
|
efficitur sem. Ut quis placerat quam. Donec maximus a risus sed
|
||||||
|
posuere. Curabitur pretium a diam non aliquet.
|
||||||
|
|
||||||
|
Class aptent taciti sociosqu ad litora torquent per conubia nostra,
|
||||||
|
per inceptos himenaeos. Morbi volutpat felis leo, vel ultrices orci
|
||||||
|
bibendum ac. Integer eu mattis urna. Donec dictum vehicula
|
||||||
|
fermentum. Pellentesque a rutrum ipsum. Donec ultricies elit purus,
|
||||||
|
eget viverra tellus tristique sed. In hac habitasse platea dictumst.
|
||||||
|
Duis elementum semper elit, sit amet rhoncus lacus dictum ac. Nunc
|
||||||
|
pretium enim ac urna efficitur, eget facilisis enim interdum.
|
||||||
|
|
||||||
|
Vivamus vel lectus lacus. Praesent vestibulum vel ligula eget
|
||||||
|
cursus. Quisque eu dignissim erat. Quisque maximus arcu eu turpis
|
||||||
|
pulvinar egestas. Nam aliquet neque sed tellus finibus mollis.
|
||||||
|
Phasellus consequat nibh nec ornare egestas. Donec at pellentesque
|
||||||
|
lorem.`,
|
||||||
|
want: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc
|
||||||
|
ornare, tellus vel luctus tristique, ipsum ante varius mauris, non
|
||||||
|
hendrerit tellus urna quis ex. Donec efficitur arcu sed iaculis
|
||||||
|
lobortis. Phasellus facilisis vitae mi quis accumsan. Suspendisse
|
||||||
|
rhoncus viverra odio ultricies rhoncus. Cras laoreet tortor
|
||||||
|
vestibulum pharetra luctus. Vivamus sit amet volutpat elit.
|
||||||
|
Suspendisse feugiat lectus id arcu sollicitudin tincidunt. Duis ut
|
||||||
|
sem auctor orci sodales varius in ac odio. Nullam finibus odio at
|
||||||
|
lacus tristique malesuada.
|
||||||
|
|
||||||
|
Morbi nisl nulla, euismod eu enim in, tincidunt varius turpis. Morbi
|
||||||
|
ullamcorper tortor mi, ut aliquam metus posuere vel. Etiam vel dui
|
||||||
|
at quam placerat sollicitudin. Proin aliquam justo vitae mauris
|
||||||
|
gravida porta. Praesent hendrerit egestas ligula, faucibus tincidunt
|
||||||
|
tortor aliquet at. Ut luctus vehicula arcu eget cursus. Suspendisse
|
||||||
|
eget enim mollis, condimentum lacus eu, viverra nulla. Aenean vel
|
||||||
|
sapien eget enim convallis accumsan. Donec dictum ullamcorper leo
|
||||||
|
placerat sollicitudin. Pellentesque habitant morbi tristique
|
||||||
|
senectus et netus et malesuada fames ac turpis egestas. Vestibulum
|
||||||
|
volutpat mattis est, a feugiat purus feugiat at. Quisque at velit ut
|
||||||
|
mauris convallis sodales a et erat. Mauris condimentum augue sit
|
||||||
|
amet arcu sodales, aliquet ultrices ipsum tempor. Donec scelerisque
|
||||||
|
mi ligula, vel volutpat velit posuere a. Sed faucibus dui pulvinar
|
||||||
|
lorem commodo egestas. In facilisis suscipit lacus non suscipit.
|
||||||
|
|
||||||
|
Nunc dictum est nulla, a rhoncus mi posuere id. Morbi at tempus
|
||||||
|
augue. Quisque ac nibh auctor velit auctor placerat id non eros.
|
||||||
|
Nulla condimentum quam id risus suscipit, ut fermentum mauris
|
||||||
|
lacinia. Vestibulum suscipit rutrum ex, sed vulputate nisi tempus
|
||||||
|
ultricies. Sed id ante pretium, accumsan sapien eget, malesuada
|
||||||
|
quam. Phasellus quis commodo enim. Vivamus in purus ac lorem ornare
|
||||||
|
posuere non eu quam. Sed arcu tortor, gravida quis fringilla nec,
|
||||||
|
ultricies et sem. Pellentesque arcu enim, tempor id nisl at, rhoncus
|
||||||
|
efficitur sem. Ut quis placerat quam. Donec maximus a risus sed
|
||||||
|
posuere. Curabitur pretium a diam non aliquet.
|
||||||
|
|
||||||
|
Class aptent taciti sociosqu ad litora torquent per conubia nostra,
|
||||||
|
per inceptos himenaeos. Morbi volutpat felis leo, vel ultrices orci
|
||||||
|
bibendum ac. Integer eu mattis urna. Donec dictum vehicula
|
||||||
|
fermentum. Pellentesque a rutrum ipsum. Donec ultricies elit purus,
|
||||||
|
eget viverra tellus tristique sed. In hac habitasse platea dictumst.
|
||||||
|
Duis elementum semper elit, sit amet rhoncus lacus dictum ac. Nunc
|
||||||
|
pretium enim ac urna efficitur, eget facilisis enim interdum.
|
||||||
|
|
||||||
|
Vivamus vel lectus lacus. Praesent vestibulum vel ligula eget
|
||||||
|
cursus. Quisque eu dignissim erat. Quisque maximus arcu eu turpis
|
||||||
|
pulvinar egestas. Nam aliquet neque sed tellus finibus mollis.
|
||||||
|
Phasellus consequat nibh nec ornare egestas. Donec at pellentesque
|
||||||
|
lorem.`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var stringfTestCases = []struct {
|
var stringfTestCases = []struct {
|
||||||
@@ -197,8 +364,7 @@ var stringfTestCases = []struct {
|
|||||||
]
|
]
|
||||||
}`,
|
}`,
|
||||||
a: []interface{}{"world", 42},
|
a: []interface{}{"world", 42},
|
||||||
want: `
|
want: `{
|
||||||
{
|
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
42
|
42
|
||||||
@@ -208,6 +374,41 @@ var stringfTestCases = []struct {
|
|||||||
{
|
{
|
||||||
name: "multi-line space indented",
|
name: "multi-line space indented",
|
||||||
s: `
|
s: `
|
||||||
|
{
|
||||||
|
"hello": "%s",
|
||||||
|
"foo": [
|
||||||
|
%d
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
a: []interface{}{"world", 42},
|
||||||
|
want: `{
|
||||||
|
"hello": "world",
|
||||||
|
"foo": [
|
||||||
|
42
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "multi-line space indented without any leading line-breaks",
|
||||||
|
s: ` {
|
||||||
|
"hello": "%s",
|
||||||
|
"foo": [
|
||||||
|
%d
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
a: []interface{}{"world", 42},
|
||||||
|
want: `{
|
||||||
|
"hello": "world",
|
||||||
|
"foo": [
|
||||||
|
42
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "multi-line space indented with leading line-breaks",
|
||||||
|
s: `
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"hello": "%s",
|
"hello": "%s",
|
||||||
"foo": [
|
"foo": [
|
||||||
@@ -216,6 +417,7 @@ var stringfTestCases = []struct {
|
|||||||
}`,
|
}`,
|
||||||
a: []interface{}{"world", 42},
|
a: []interface{}{"world", 42},
|
||||||
want: `
|
want: `
|
||||||
|
|
||||||
{
|
{
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
@@ -233,7 +435,43 @@ var stringfTestCases = []struct {
|
|||||||
]
|
]
|
||||||
}`,
|
}`,
|
||||||
a: []interface{}{"world", 42},
|
a: []interface{}{"world", 42},
|
||||||
|
want: `{
|
||||||
|
"hello": "world",
|
||||||
|
"foo": [
|
||||||
|
42
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "multi-line tab indented without any leading line-breaks",
|
||||||
|
s: ` {
|
||||||
|
"hello": "%s",
|
||||||
|
"foo": [
|
||||||
|
%d
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
a: []interface{}{"world", 42},
|
||||||
|
want: `{
|
||||||
|
"hello": "world",
|
||||||
|
"foo": [
|
||||||
|
42
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "multi-line tab indented with leading line-breaks",
|
||||||
|
s: `
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
"hello": "%s",
|
||||||
|
"foo": [
|
||||||
|
%d
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
a: []interface{}{"world", 42},
|
||||||
want: `
|
want: `
|
||||||
|
|
||||||
{
|
{
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
@@ -251,8 +489,7 @@ var stringfTestCases = []struct {
|
|||||||
]
|
]
|
||||||
}`,
|
}`,
|
||||||
a: []interface{}{"world", 42},
|
a: []interface{}{"world", 42},
|
||||||
want: `
|
want: `{
|
||||||
{
|
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
42
|
42
|
||||||
@@ -271,8 +508,7 @@ var stringfTestCases = []struct {
|
|||||||
]
|
]
|
||||||
}`,
|
}`,
|
||||||
a: []interface{}{"world", 42},
|
a: []interface{}{"world", 42},
|
||||||
want: `
|
want: `{
|
||||||
{
|
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
|
|
||||||
@@ -293,8 +529,7 @@ var stringfTestCases = []struct {
|
|||||||
]
|
]
|
||||||
}`,
|
}`,
|
||||||
a: []interface{}{"world", 42},
|
a: []interface{}{"world", 42},
|
||||||
want: `
|
want: `{
|
||||||
{
|
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
"foo": [
|
"foo": [
|
||||||
|
|
||||||
@@ -311,8 +546,7 @@ var stringfTestCases = []struct {
|
|||||||
foo
|
foo
|
||||||
%d`,
|
%d`,
|
||||||
a: []interface{}{"world", 42},
|
a: []interface{}{"world", 42},
|
||||||
want: `
|
want: ` hello
|
||||||
hello
|
|
||||||
world
|
world
|
||||||
foo
|
foo
|
||||||
42`,
|
42`,
|
||||||
@@ -325,20 +559,134 @@ world
|
|||||||
foo
|
foo
|
||||||
%d`,
|
%d`,
|
||||||
a: []interface{}{"world", 42},
|
a: []interface{}{"world", 42},
|
||||||
want: `
|
want: ` hello
|
||||||
hello
|
|
||||||
world
|
world
|
||||||
foo
|
foo
|
||||||
42`,
|
42`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "long block of text",
|
||||||
|
s: `
|
||||||
|
Lorem %s dolor sit amet, consectetur adipiscing elit. Nunc
|
||||||
|
ornare, tellus vel luctus tristique, ipsum ante varius mauris, non
|
||||||
|
hendrerit tellus urna quis ex. %s efficitur arcu sed iaculis
|
||||||
|
lobortis. Phasellus facilisis vitae mi quis accumsan. Suspendisse
|
||||||
|
rhoncus viverra odio ultricies rhoncus. Cras laoreet tortor
|
||||||
|
vestibulum pharetra luctus. Vivamus sit amet volutpat elit.
|
||||||
|
Suspendisse feugiat lectus id arcu sollicitudin tincidunt. Duis ut
|
||||||
|
sem auctor orci sodales varius in ac odio. Nullam finibus odio at
|
||||||
|
lacus tristique malesuada.
|
||||||
|
|
||||||
|
Morbi nisl nulla, euismod eu enim in, tincidunt varius turpis. Morbi
|
||||||
|
ullamcorper tortor mi, ut aliquam metus posuere vel. Etiam vel dui
|
||||||
|
at quam placerat sollicitudin. Proin aliquam justo vitae mauris
|
||||||
|
gravida porta. Praesent hendrerit egestas ligula, faucibus tincidunt
|
||||||
|
tortor aliquet at. Ut luctus vehicula arcu eget cursus. Suspendisse
|
||||||
|
eget enim mollis, condimentum lacus eu, viverra nulla. Aenean vel
|
||||||
|
sapien eget enim convallis accumsan. Donec dictum ullamcorper leo
|
||||||
|
placerat sollicitudin. Pellentesque habitant morbi tristique
|
||||||
|
senectus et netus et malesuada fames ac turpis egestas. Vestibulum
|
||||||
|
volutpat mattis est, a feugiat purus feugiat at. Quisque at velit ut
|
||||||
|
mauris convallis sodales a et erat. Mauris condimentum augue sit
|
||||||
|
amet arcu sodales, aliquet ultrices ipsum tempor. Donec scelerisque
|
||||||
|
mi ligula, vel volutpat velit posuere a. Sed faucibus dui pulvinar
|
||||||
|
lorem commodo egestas. In facilisis suscipit lacus non suscipit.
|
||||||
|
|
||||||
|
Nunc dictum est nulla, a rhoncus mi posuere id. Morbi at tempus
|
||||||
|
augue. Quisque ac nibh auctor velit auctor placerat id non eros.
|
||||||
|
Nulla condimentum quam id risus suscipit, ut fermentum mauris
|
||||||
|
lacinia. Vestibulum suscipit rutrum ex, sed vulputate nisi tempus
|
||||||
|
ultricies. Sed id ante pretium, accumsan sapien eget, malesuada
|
||||||
|
quam. Phasellus quis commodo enim. Vivamus in purus ac lorem ornare
|
||||||
|
posuere non eu quam. Sed arcu tortor, gravida quis fringilla nec,
|
||||||
|
ultricies et sem. Pellentesque arcu enim, tempor id nisl at, rhoncus
|
||||||
|
efficitur sem. Ut quis placerat quam. Donec maximus a risus sed
|
||||||
|
posuere. Curabitur pretium a diam non aliquet.
|
||||||
|
|
||||||
|
Class aptent taciti sociosqu ad litora torquent per conubia nostra,
|
||||||
|
per inceptos himenaeos. Morbi volutpat felis leo, vel ultrices orci
|
||||||
|
bibendum ac. Integer eu mattis urna. Donec dictum vehicula
|
||||||
|
fermentum. Pellentesque a rutrum ipsum. Donec ultricies elit purus,
|
||||||
|
eget viverra tellus tristique sed. In hac habitasse platea dictumst.
|
||||||
|
Duis elementum semper elit, sit amet rhoncus lacus dictum ac. Nunc
|
||||||
|
pretium enim ac urna efficitur, eget facilisis enim interdum.
|
||||||
|
|
||||||
|
Vivamus vel lectus lacus. Praesent vestibulum vel ligula eget
|
||||||
|
cursus. Quisque eu dignissim erat. Quisque maximus arcu eu turpis
|
||||||
|
pulvinar egestas. Nam aliquet neque sed tellus finibus mollis.
|
||||||
|
Phasellus consequat nibh nec ornare egestas. Donec at pellentesque
|
||||||
|
lorem.`,
|
||||||
|
a: []interface{}{"ipsum", "Donec"},
|
||||||
|
want: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc
|
||||||
|
ornare, tellus vel luctus tristique, ipsum ante varius mauris, non
|
||||||
|
hendrerit tellus urna quis ex. Donec efficitur arcu sed iaculis
|
||||||
|
lobortis. Phasellus facilisis vitae mi quis accumsan. Suspendisse
|
||||||
|
rhoncus viverra odio ultricies rhoncus. Cras laoreet tortor
|
||||||
|
vestibulum pharetra luctus. Vivamus sit amet volutpat elit.
|
||||||
|
Suspendisse feugiat lectus id arcu sollicitudin tincidunt. Duis ut
|
||||||
|
sem auctor orci sodales varius in ac odio. Nullam finibus odio at
|
||||||
|
lacus tristique malesuada.
|
||||||
|
|
||||||
|
Morbi nisl nulla, euismod eu enim in, tincidunt varius turpis. Morbi
|
||||||
|
ullamcorper tortor mi, ut aliquam metus posuere vel. Etiam vel dui
|
||||||
|
at quam placerat sollicitudin. Proin aliquam justo vitae mauris
|
||||||
|
gravida porta. Praesent hendrerit egestas ligula, faucibus tincidunt
|
||||||
|
tortor aliquet at. Ut luctus vehicula arcu eget cursus. Suspendisse
|
||||||
|
eget enim mollis, condimentum lacus eu, viverra nulla. Aenean vel
|
||||||
|
sapien eget enim convallis accumsan. Donec dictum ullamcorper leo
|
||||||
|
placerat sollicitudin. Pellentesque habitant morbi tristique
|
||||||
|
senectus et netus et malesuada fames ac turpis egestas. Vestibulum
|
||||||
|
volutpat mattis est, a feugiat purus feugiat at. Quisque at velit ut
|
||||||
|
mauris convallis sodales a et erat. Mauris condimentum augue sit
|
||||||
|
amet arcu sodales, aliquet ultrices ipsum tempor. Donec scelerisque
|
||||||
|
mi ligula, vel volutpat velit posuere a. Sed faucibus dui pulvinar
|
||||||
|
lorem commodo egestas. In facilisis suscipit lacus non suscipit.
|
||||||
|
|
||||||
|
Nunc dictum est nulla, a rhoncus mi posuere id. Morbi at tempus
|
||||||
|
augue. Quisque ac nibh auctor velit auctor placerat id non eros.
|
||||||
|
Nulla condimentum quam id risus suscipit, ut fermentum mauris
|
||||||
|
lacinia. Vestibulum suscipit rutrum ex, sed vulputate nisi tempus
|
||||||
|
ultricies. Sed id ante pretium, accumsan sapien eget, malesuada
|
||||||
|
quam. Phasellus quis commodo enim. Vivamus in purus ac lorem ornare
|
||||||
|
posuere non eu quam. Sed arcu tortor, gravida quis fringilla nec,
|
||||||
|
ultricies et sem. Pellentesque arcu enim, tempor id nisl at, rhoncus
|
||||||
|
efficitur sem. Ut quis placerat quam. Donec maximus a risus sed
|
||||||
|
posuere. Curabitur pretium a diam non aliquet.
|
||||||
|
|
||||||
|
Class aptent taciti sociosqu ad litora torquent per conubia nostra,
|
||||||
|
per inceptos himenaeos. Morbi volutpat felis leo, vel ultrices orci
|
||||||
|
bibendum ac. Integer eu mattis urna. Donec dictum vehicula
|
||||||
|
fermentum. Pellentesque a rutrum ipsum. Donec ultricies elit purus,
|
||||||
|
eget viverra tellus tristique sed. In hac habitasse platea dictumst.
|
||||||
|
Duis elementum semper elit, sit amet rhoncus lacus dictum ac. Nunc
|
||||||
|
pretium enim ac urna efficitur, eget facilisis enim interdum.
|
||||||
|
|
||||||
|
Vivamus vel lectus lacus. Praesent vestibulum vel ligula eget
|
||||||
|
cursus. Quisque eu dignissim erat. Quisque maximus arcu eu turpis
|
||||||
|
pulvinar egestas. Nam aliquet neque sed tellus finibus mollis.
|
||||||
|
Phasellus consequat nibh nec ornare egestas. Donec at pellentesque
|
||||||
|
lorem.`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBytes(t *testing.T) {
|
func TestBytes(t *testing.T) {
|
||||||
for _, tt := range stringTestCases {
|
for _, tt := range stringTestCases {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got := Bytes([]byte(tt.s))
|
got := Bytes(tt.s)
|
||||||
|
|
||||||
assert.Equal(t, []byte(tt.want), got)
|
assert.IsType(t, []byte{}, got)
|
||||||
|
assert.Equal(t, tt.want, string(got))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBytesf(t *testing.T) {
|
||||||
|
for _, tt := range stringfTestCases {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got := Bytesf(tt.s, tt.a...)
|
||||||
|
|
||||||
|
assert.IsType(t, []byte{}, got)
|
||||||
|
assert.Equal(t, tt.want, string(got))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -348,6 +696,7 @@ func TestString(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got := String(tt.s)
|
got := String(tt.s)
|
||||||
|
|
||||||
|
assert.IsType(t, "", got)
|
||||||
assert.Equal(t, tt.want, got)
|
assert.Equal(t, tt.want, got)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -358,6 +707,63 @@ func TestStringf(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got := Stringf(tt.s, tt.a...)
|
got := Stringf(tt.s, tt.a...)
|
||||||
|
|
||||||
|
assert.IsType(t, "", got)
|
||||||
|
assert.Equal(t, tt.want, got)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrint(t *testing.T) {
|
||||||
|
for _, tt := range stringTestCases {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, err := fakeio.Stdout().Do(func() {
|
||||||
|
_, _ = Print(tt.s, 5, tt.s)
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.IsType(t, "", got)
|
||||||
|
assert.Equal(t, tt.want+"5"+tt.want, got)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrintf(t *testing.T) {
|
||||||
|
for _, tt := range stringfTestCases {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, err := fakeio.Stdout().Do(func() {
|
||||||
|
_, _ = Printf(tt.s, tt.a...)
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.IsType(t, "", got)
|
||||||
|
assert.Equal(t, tt.want, got)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFprint(t *testing.T) {
|
||||||
|
for _, tt := range stringTestCases {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
|
||||||
|
_, _ = Fprint(&buf, tt.s, 5, tt.s)
|
||||||
|
got := buf.String()
|
||||||
|
|
||||||
|
assert.IsType(t, "", got)
|
||||||
|
assert.Equal(t, tt.want+"5"+tt.want, got)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFprintf(t *testing.T) {
|
||||||
|
for _, tt := range stringfTestCases {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
|
||||||
|
_, _ = Fprintf(&buf, tt.s, tt.a...)
|
||||||
|
got := buf.String()
|
||||||
|
|
||||||
|
assert.IsType(t, "", got)
|
||||||
assert.Equal(t, tt.want, got)
|
assert.Equal(t, tt.want, got)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -366,10 +772,8 @@ func TestStringf(t *testing.T) {
|
|||||||
func BenchmarkBytes(b *testing.B) {
|
func BenchmarkBytes(b *testing.B) {
|
||||||
for _, tt := range stringTestCases {
|
for _, tt := range stringTestCases {
|
||||||
b.Run(tt.name, func(b *testing.B) {
|
b.Run(tt.name, func(b *testing.B) {
|
||||||
input := []byte(tt.s)
|
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
Bytes(input)
|
Bytes(tt.s)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user