Giter Club home page Giter Club logo

heredoc's Introduction

heredoc

Version Workflow Result Go Reference

About

Package heredoc provides the here-document with keeping indent.

Import

import "github.com/MakeNowJust/heredoc/v2"

Example

package main

import (
	"fmt"

	"github.com/MakeNowJust/heredoc/v2"
)

func main() {
	fmt.Println(heredoc.Doc(`
		Lorem ipsum dolor sit amet, consectetur adipisicing elit,
		sed do eiusmod tempor incididunt ut labore et dolore magna
		aliqua. Ut enim ad minim veniam, ...
	`))
	// Output:
	// Lorem ipsum dolor sit amet, consectetur adipisicing elit,
	// sed do eiusmod tempor incididunt ut labore et dolore magna
	// aliqua. Ut enim ad minim veniam, ...
	//
}

API Document

heredoc package - github.com/MakeNowJust/heredoc/v2 - pkg.go.dev

License

This software is released under the MIT License, see LICENSE.

heredoc's People

Contributors

jaybeale avatar makenowjust avatar spenserblack avatar tcharding avatar yarcat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

heredoc's Issues

Not sure if module should behave such way?

Describe the bug

I'm not sure if such behaviour is inconsistent?

To Reproduce

Code:

package main

import (
	"fmt"

	"github.com/MakeNowJust/heredoc/v2"
)

func main() {
	fmt.Println(heredoc.Doc(`
			Is it a basic indentation level or not?
		  Minus one tab plus two spaces.
			To compare.
	`))
}

Expected:

	Is it a basic indentation level or not?
 Minus one tab plus two spaces.
	To compare.

Actual:

Is it a basic indentation level or not?
 Minus one tab plus two spaces.
To compare.

Environment

Wrong character is produced when indent contains full-width (zenkaku) space

Describe the bug

Wrong character is produced by heredoc.Doc function when indent contains full-width (zenkaku, u+3000) space.

To Reproduce

With:

package main

import (
	"fmt"

	"github.com/MakeNowJust/heredoc"
)

func main() {
	fmt.Printf("%#+v\n", heredoc.Doc("\n\u3000hello"))
}

Shows this result: "\x80\x80hello". "\x80" is wrong character.

Expected behavior

"hello" is correct result.

invalid v2 versioning

Describe the bug

$ go get -u github.com/MakeNowJust/[email protected]
go: finding github.com/MakeNowJust/heredoc v2.0.1
go: finding github.com/MakeNowJust/heredoc v2.0.1
go get github.com/MakeNowJust/[email protected]: github.com/MakeNowJust/[email protected]: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher
you should make /v2 dir or v2 branch.

e.g. favclip/ucon#33

To Reproduce

Code: same as below

Expected: go get succeed

Actual: raise error

Environment

  • OS: macOS
  • Go: 1.13.4
  • Version: 2.0.1

Using heredoc inside heredoc with JSON : error: invalid character '\n' in string literal after unmarshalling

Describe the bug

When using a heredoc.Docf as a string interpolation variable for another heredoc.Docf (for instance in the context of building json payloads) with the purpose of (un)marshaling, when there are newlines, the code crashes with error: invalid character '\n' in string literal.

After looking at this StackOverflow, it seems it's because we need to double escape the newlines in JSON string literals. So we should provide an example of how to work with JSON in such a way, as I find heredoc to be very convenient for writing JSON-related tests.

Can we add a new method heredoc.Json/Jsonf( to handle this case + an example in the readme ? Or is there already a workaround to get this working with docf (in which case it would be nice to add this somewhere in the readme) ?

To Reproduce

Code:

import ("github.com/MakeNowJust/heredoc/v2")
func TestHeredocInsideHeredoc(t *testing.T) {
	interpolationHeredoc := heredoc.Docf(`
		Hello,
		%s
	`, "World")
	topLevelHeredoc := heredoc.Docf(`
		{
			"type": "top-level",
			"content": "%s",
		}`, interpolationHeredoc,
	)
	expectedJson := `
		{
			"type": "top-level",
			"content": "Hello,\nWorld"
		}
	`

	expectedBytes := []byte(expectedJson)
	var expectedObject map[string]interface{}
	err := json.Unmarshal(expectedBytes, &expectedObject)
	if err != nil {
		fmt.Println("error:", err)
	}

	expectedBytes = []byte(topLevelHeredoc)
	var actualObject map[string]interface{}
	err = json.Unmarshal(expectedBytes, &actualObject)
	if err != nil {
		fmt.Println("error:", err)
	}

	if diff := deep.Equal(expectedObject, actualObject); diff != nil {
		t.Error(diff)
	}
}

Expected:

OK

Actual:

error: invalid character '\n' in string literal
--- FAIL: TestHeredocInsideHeredoc (0.00s)
    /Users/Cyril/dev/dont-slack-evil/apphome/apphome_test.go:49: [map[content:map[content:Hello,
        World type:top-level] type:nested] != <nil map>]

Environment

  • OS: [e.g. Windows, macOS, Linux]
  • Go: [e.g. 1.12.9]
  • Version: [e.g. 1.0.0]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.