-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# These are supported funding model platforms | ||
|
||
github: [changkun] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] | ||
patreon: # Replace with a single Patreon username | ||
open_collective: # Replace with a single Open Collective username | ||
ko_fi: # Replace with a single Ko-fi username | ||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel | ||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry | ||
liberapay: # Replace with a single Liberapay username | ||
issuehunt: # Replace with a single IssueHunt username | ||
otechie: # Replace with a single Otechie username | ||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2021 The golang.design Initiative authors. | ||
# All rights reserved. Use of this source code is governed | ||
# by a GNU GPL-3.0 license that can be found in the LICENSE file. | ||
# | ||
# Written by Changkun Ou <changkun.de> | ||
|
||
name: code2img | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
platform_test: | ||
|
||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, macos-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v2 | ||
with: | ||
stable: 'false' | ||
go-version: '1.16.0' | ||
|
||
- name: Test | ||
run: | | ||
go test -v -covermode=atomic ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2021 The golang.design Initiative authors. | ||
// All rights reserved. Use of this source code is governed | ||
// by a GNU GPL-3.0 license that can be found in the LICENSE file. | ||
// | ||
// Written by Changkun Ou <changkun.de> | ||
|
||
package code2img_test | ||
|
||
import ( | ||
"bytes" | ||
"image/png" | ||
"math" | ||
"os" | ||
"testing" | ||
|
||
"golang.design/x/code2img" | ||
) | ||
|
||
func TestRender(t *testing.T) { | ||
got, err := code2img.Render(`import "golang.design/x/code2img`) | ||
if err != nil { | ||
t.Fatalf("render failed: %v", err) | ||
} | ||
|
||
imgGot, err := png.Decode(bytes.NewReader(got)) | ||
if err != nil { | ||
t.Fatalf("cannot read rendered image: %v", err) | ||
} | ||
|
||
want, err := os.ReadFile("testdata.png") | ||
if err != nil { | ||
t.Fatalf("cannot read gold test file: %v", err) | ||
} | ||
|
||
imgWant, err := png.Decode(bytes.NewReader(want)) | ||
if err != nil { | ||
t.Fatalf("cannot read gold image: %v", err) | ||
} | ||
|
||
if math.Abs(float64(imgGot.Bounds().Dx()-imgWant.Bounds().Dx())) > 5 || | ||
math.Abs(float64(imgGot.Bounds().Dy()-imgWant.Bounds().Dy())) > 5 { | ||
|
||
err := os.WriteFile("got.png", got, os.ModePerm) | ||
if err != nil { | ||
t.Errorf("failed to write image: %v", err) | ||
} | ||
|
||
t.Fatalf("image size does not match: got %+v, want %+v", imgGot.Bounds(), imgWant.Bounds()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
module golang.design/x/code2img | ||
|
||
go 1.15 | ||
go 1.16 | ||
|
||
require ( | ||
github.com/chromedp/cdproto v0.0.0-20200116234248-4da64dd111ac | ||
github.com/chromedp/chromedp v0.5.3 | ||
github.com/gin-gonic/gin v1.6.3 | ||
github.com/google/uuid v1.1.2 | ||
github.com/sirupsen/logrus v1.7.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.