diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7509ae7..3accaec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,35 @@ jobs: with: go-version: '1.21' - name: Test all - run: go version && go mod tidy && go test -v ./... + run: go version && go mod tidy && go test -v -covermode=count -coverprofile=coverage.out ./... + - name: Upload coverage to Coveralls + uses: coverallsapp/github-action@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + # If your repo is private, uncomment the next line and set the secret + # coveralls-token: ${{ secrets.COVERALLS_REPO_TOKEN }} + path-to-lcov: coverage.out + benchmark-tests: + name: Run benchmark tests on linux + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.7 + - name: Set up Go + uses: actions/setup-go@v5.2.0 + with: + go-version: '1.21' + - name: Benchmark all + run: go test -bench=. -run=^$ ./... -cpu 1 | tee benchmark_output.txt + - name: Store and Track Benchmarks + uses: benchmark-action/github-action-benchmark@v1 + with: + name: Go Benchmark Results + tool: 'go' + output-file-path: benchmark_output.txt + github-token: ${{ secrets.GITHUB_TOKEN }} + auto-push: true + # This saves results directly into a "benchmark" folder on your gh-pages branch + benchmark-data-dir-path: 'benchmarks' #all-tests-windows: # name: Run all tests on windows diff --git a/README.md b/README.md index fb19d41..c635de8 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,13 @@ # Wissance/StringFormatter +[![Awesome Package](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) ![GitHub go.mod Go version (subdirectory of monorepo)](https://img.shields.io/github/go-mod/go-version/wissance/stringFormatter?style=plastic) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/wissance/stringFormatter?style=plastic) ![GitHub issues](https://img.shields.io/github/issues/wissance/stringFormatter?style=plastic) ![GitHub Release Date](https://img.shields.io/github/release-date/wissance/stringFormatter) -[![Wissance.WebApiToolkit CI](https://github.com/Wissance/stringFormatter/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Wissance/stringFormatter/actions/workflows/ci.yml) +[![Wissance.StringFormatter CI](https://github.com/Wissance/stringFormatter/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Wissance/stringFormatter/actions/workflows/ci.yml) +[![Go Report Card](https://goreportcard.com/badge/github.com/wissance/stringFormatter)](https://goreportcard.com/report/github.com/wissance/stringFormatter) +[![Coverage Status](https://coveralls.io/repos/github/Wissance/stringFormatter/badge.svg?branch=master)](https://coveralls.io/github/Wissance/stringFormatter?branch=master) +[![Go Benchmarks](https://img.shields.io/badge/Benchmarks-View_Report-green?style=plastic)](https://raw.githubusercontent.com/Wissance/stringFormatter/refs/heads/gh-pages/benchmarks/data.js) ![String Formatter: a convenient string formatting tool](img/sf_logo_sm.png) @@ -13,6 +17,11 @@ 3. Use for **template-based src code generator** 4. Other text proccessing +Other important resources: +* [Go Report Card A+](https://goreportcard.com/report/github.com/wissance/stringFormatter) +* [Coverage > 80%](https://coveralls.io/github/Wissance/stringFormatter) + + ## ✨ 1 Features 🔤 Flexible Syntax: Supports both indexed / positional (`{0}`) and named (`{user}`) *placeholders* in templates. @@ -158,9 +167,11 @@ result2 := sf.SliceSameTypeToString(&numSlice, &separator) ## 📊 5 Benchmarks The library is optimized for high-load scenarios. Key benchmarks show significant performance gains (performance could be differ due to 1. different CPU architectures 2. statistics): -Formatting (Format) vs fmt.Sprintf: 3-5x faster for complex templates. +Formatting (Format) vs `fmt.Sprintf`: `3-5x` faster for complex templates. Slices (SliceToString) vs manual fmt-based joining: from `2.5` faster up to 20 items. +These benchmarks tests are running with githun ci on push to `develop` or `master`, [see](https://github.com/Wissance/stringFormatter/actions) + Run the benchmarks yourself: ```bash go test -bench=Format -benchmem -cpu 1 @@ -178,6 +189,7 @@ Some benchmark screenshots: 3. `SliceToStr`: ![SliceToStr benchmarks](img/slice2str_benchmarks.png) + ## 📄 6 License This project is licensed under the MIT License - see the LICENSE file for details. diff --git a/maptostring.go b/maptostring.go index d16d665..6fb80f5 100644 --- a/maptostring.go +++ b/maptostring.go @@ -12,7 +12,7 @@ const ( // MapToString - format map keys and values according to format, joining parts with separator. // Format should contain key and value placeholders which will be used for formatting, e.g. // "{key} : {value}", or "{value}", or "{key} => {value}". -// Parts order in resulting string is not guranteed. +// Parts order in resulting string is not guaranteed. func MapToString[ K string | int | uint | int32 | int64 | uint32 | uint64, V any,