Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: makenowjust/heredoc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0
Choose a base ref
...
head repository: makenowjust/heredoc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.0
Choose a head ref
  • 5 commits
  • 5 files changed
  • 1 contributor

Commits on Aug 23, 2019

  1. Format README.md

    makenowjust committed Aug 23, 2019
    Copy the full SHA
    e412be8 View commit details
  2. Update issue templates

    makenowjust authored Aug 23, 2019
    Copy the full SHA
    fd11982 View commit details
  3. Replace unicode.IsSpace with my own implementation

    Fixed #6
    
    unicode.IsSpace handles unicode spaces, but it is harmful for heredoc.
    makenowjust committed Aug 23, 2019
    Copy the full SHA
    4d4f34d View commit details
  4. Copy the full SHA
    739eee8 View commit details
  5. Update issue template

    makenowjust committed Aug 23, 2019
    Copy the full SHA
    aef3061 View commit details
Showing with 49 additions and 6 deletions.
  1. +29 −0 .github/ISSUE_TEMPLATE/bug_report.md
  2. +1 −1 README.md
  3. +1 −1 example_test.go
  4. +17 −4 heredoc.go
  5. +1 −0 heredoc_test.go
29 changes: 29 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: MakeNowJust
---

## Describe the bug

A clear and concise description of what the bug is.

## To Reproduce

**Code**:

```go
// Minimal code for reproduce the bug
```

**Expected**:

**Actual**:

## Environment

- OS: [e.g. Windows, macOS, Linux]
- Go: [e.g. 1.12.9]
- Version: [e.g. 1.0.0]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ $ go get github.com/MakeNowJust/heredoc
## Import

```go
// usual
import "github.com/MakeNowJust/heredoc"
```

@@ -26,6 +25,7 @@ package main

import (
"fmt"

"github.com/MakeNowJust/heredoc"
)

2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ func ExampleDoc_spec() {
func ExampleDocf() {
libName := "github.com/MakeNowJust/heredoc"
author := "TSUYUSATO Kitsune (@MakeNowJust)"
fmt.Printf(heredoc.Docf(`
fmt.Print(heredoc.Docf(`
Library Name : %s
Author : %s
Repository URL: http://%s.git
21 changes: 17 additions & 4 deletions heredoc.go
Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@ package heredoc
import (
"fmt"
"strings"
"unicode"
)

const maxInt = int(^uint(0) >> 1)
@@ -54,6 +53,20 @@ func Doc(raw string) string {
return strings.Join(lines, "\n")
}

// isSpace checks whether the rune represents space or not.
// Only white spcaes (U+0020) and horizontal tabs are treated as space character.
// It is the same as Go.
//
// See https://github.com/MakeNowJust/heredoc/issues/6#issuecomment-524231625.
func isSpace(r rune) bool {
switch r {
case ' ', '\t':
return true
default:
return false
}
}

// getMinIndent calculates the minimum indentation in lines, excluding empty lines.
func getMinIndent(lines []string, skipFirstLine bool) int {
minIndentSize := maxInt
@@ -64,9 +77,9 @@ func getMinIndent(lines []string, skipFirstLine bool) int {
}

indentSize := 0
for _, r := range []rune(line) {
if unicode.IsSpace(r) {
indentSize += 1
for _, r := range line {
if isSpace(r) {
indentSize++
} else {
break
}
1 change: 1 addition & 0 deletions heredoc_test.go
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ var tests = []testCase{
Foo
Bar
`, "Foo\nBar\n"},
{"\n\u3000zenkaku space", "\u3000zenkaku space"},
}

func TestDoc(t *testing.T) {