Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lang): show expected output for examples #27

Merged
merged 6 commits into from
Nov 25, 2020

Conversation

terrabitz
Copy link
Contributor

@terrabitz terrabitz commented Nov 22, 2020

Closes #26

This MR includes example output along with the code that generates that output. Given foo.go:

package foo

import "fmt"

func Hello(name string) string {
	return fmt.Sprintf("Hello %s!", name)
}

and foo_test.go:

package foo

import "fmt"

func ExampleHello() {
	fmt.Println(Hello("foo"))
	// Output: Hello foo!
}

the output looks like this:

<details><summary>Example</summary>
<p>

```go
{
	fmt.Println(Hello("foo"))

}
```



Outputs:

```output
Hello foo!
```

</p>
</details>

Note, this MR also includes a go mod tidy. This might overlap with #25, so this can be altered if necessary. Additionally, I ended up using the markdown code fence type output as a descriptor, but I don't know if there's a better descriptor to use here.

@terrabitz
Copy link
Contributor Author

@princjef This should be ready to merge. I don't know why the pipeline's failing, but my guess is it's not directly connected to the changes I made.

Copy link
Owner

@princjef princjef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice change :) As long as we can make the output look reasonable for examples with no output I'm good with it.

lang/example.go Show resolved Hide resolved
templates/example.gotxt Outdated Show resolved Hide resolved
templates/example.gotxt Outdated Show resolved Hide resolved
templates/example.gotxt Outdated Show resolved Hide resolved
@terrabitz terrabitz force-pushed the master branch 2 times, most recently from 0ec9917 to 1fdfc24 Compare November 25, 2020 20:33
@terrabitz
Copy link
Contributor Author

Support for empty output has been added. Given the following examples:

func ExampleHello() {
	fmt.Println(Hello("foo"))
	// Output: Hello foo!
}

func ExampleHello_noOutput() {
	_ = Hello("foo")
}

func ExampleHello_comments() {
	_ = Hello("foo")
	// This returns a hello string
}

The output looks like this:

<details><summary>Example</summary>
<p>

```go
{
	fmt.Println(Hello("foo"))

}
```

#### Output

```
Hello foo!
```

</p>
</details>

<details><summary>Example</summary>
<p>

```go
{
	_ = Hello("foo")

}
```

</p>
</details>

<details><summary>Example</summary>
<p>

```go
{
	_ = Hello("foo")
}
```

</p>
</details>

Signed-off-by: Trevor Taubitz <[email protected]>
Signed-off-by: Trevor Taubitz <[email protected]>
Signed-off-by: Trevor Taubitz <[email protected]>
@terrabitz
Copy link
Contributor Author

@princjef This should be good for another round of review. I have added support for empty outputs, as well as rebased on the latest master branch to avoid merge conflicts.

@terrabitz
Copy link
Contributor Author

An update has been made to differentiate empty output and no output. Given the following examples:

func ExampleHello_emptyOutput() {
	_ = Hello("foo")
	// Output:
}

func ExampleHello_noOutput() {
	_ = Hello("foo")
}

The output is as follows:

<details><summary>Example</summary>
<p>

```go
{
	_ = Hello("foo")

}
```

#### Output

```

```

</p>
</details>

<details><summary>Example</summary>
<p>

```go
{
	_ = Hello("foo")
}
```

</p>
</details>

@terrabitz terrabitz requested a review from princjef November 25, 2020 23:45
princjef
princjef previously approved these changes Nov 25, 2020
Copy link
Owner

@princjef princjef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 💯

templates/example.gotxt Outdated Show resolved Hide resolved
princjef
princjef previously approved these changes Nov 25, 2020
@princjef
Copy link
Owner

Looks good to go! Will merge once CI checks have passed

@princjef princjef changed the title Include Example Output feat(lang): show expected output for examples Nov 25, 2020
@princjef princjef merged commit c0b3572 into princjef:master Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggestion: Include Example Outputs
2 participants