pax_global_header 0000666 0000000 0000000 00000000064 14120400617 0014505 g ustar 00root root 0000000 0000000 52 comment=b591ba0e78db7557b5d4e06cc42970d702ce0728
yaegi-0.10.0/ 0000775 0000000 0000000 00000000000 14120400617 0012661 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/.github/ 0000775 0000000 0000000 00000000000 14120400617 0014221 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/.github/ISSUE_TEMPLATE/ 0000775 0000000 0000000 00000000000 14120400617 0016404 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/.github/ISSUE_TEMPLATE/bug_report.yml 0000664 0000000 0000000 00000002625 14120400617 0021304 0 ustar 00root root 0000000 0000000 name: Bug Report
description: Create a report to help us improve
body:
- type: markdown
attributes:
value: |
⚠️ Make sure to browse the opened and closed issues before submit your issue.
- type: textarea
id: sample
attributes:
label: "The following program `sample.go` triggers an unexpected result"
value: |
package main
func main() {
// add a sample
}
render: go
validations:
required: true
- type: textarea
id: expected
attributes:
label: Expected result
description: |-
```console
$ go run ./sample.go
// output
```
placeholder: $ go run ./sample.go
render: console
validations:
required: true
- type: textarea
id: got
attributes:
label: Got
description: |-
```console
$ yaegi ./sample.go
// output
```
placeholder: $ yaegi ./sample.go
render: console
validations:
required: true
- type: input
id: version
attributes:
label: Yaegi Version
description: Can be a tag or a hash.
validations:
required: true
- type: textarea
id: additional
attributes:
label: Additional Notes
description: Use [Markdown syntax](https://help.github.com/articles/github-flavored-markdown) if needed.
validations:
required: false
yaegi-0.10.0/.github/ISSUE_TEMPLATE/config.yml 0000664 0000000 0000000 00000000521 14120400617 0020372 0 ustar 00root root 0000000 0000000 blank_issues_enabled: false
contact_links:
- name: Questions
url: https://community.traefik.io/c/yaegi
about: If you have a question, or are looking for advice, please post on our discussions forum!
- name: Documentation
url: https://pkg.go.dev/github.com/traefik/yaegi
about: Please take a look to our documenation.
yaegi-0.10.0/.github/ISSUE_TEMPLATE/feature_request.yml 0000664 0000000 0000000 00000001562 14120400617 0022336 0 ustar 00root root 0000000 0000000 name: Feature request
description: Propose a change to Yaegi
body:
- type: markdown
attributes:
value: |
⚠️ Make sure to browse the opened and closed issues before submit your issue.
- type: textarea
id: proposal
attributes:
label: Proposal
description: Write your feature request in the form of a proposal to be considered for implementation.
validations:
required: true
- type: textarea
id: background
attributes:
label: Background
description: Describe the background problem or need that led to this feature request.
validations:
required: true
- type: textarea
id: workarounds
attributes:
label: Workarounds
description: Are there any current workarounds that you're using that others in similar positions should know about?
validations:
required: true
yaegi-0.10.0/.github/workflows/ 0000775 0000000 0000000 00000000000 14120400617 0016256 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/.github/workflows/go-cross.yml 0000664 0000000 0000000 00000003623 14120400617 0020541 0 ustar 00root root 0000000 0000000 name: Build Cross OS
on:
push:
branches:
- master
pull_request:
jobs:
cross:
name: Go
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ${{ github.workspace }}/go/src/github.com/traefik/yaegi
strategy:
matrix:
go-version: [ 1.16, 1.17 ]
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
go-path-suffix: /go
- os: macos-latest
go-path-suffix: /go
- os: windows-latest
go-path-suffix: \go
steps:
# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
# https://github.com/marketplace/actions/checkout
- name: Checkout code
uses: actions/checkout@v2
with:
path: go/src/github.com/traefik/yaegi
# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ matrix.go-version }}-go-
- name: Setup GOPATH
run: go env -w GOPATH=${{ github.workspace }}${{ matrix.go-path-suffix }}
# TODO fail on windows
# - name: Tests
# run: go test -v -cover ./...
# env:
# GOPATH: ${{ github.workspace }}${{ matrix.go-path }}
- name: Build
run: go build -race -v -ldflags "-s -w" -trimpath
yaegi-0.10.0/.github/workflows/main.yml 0000664 0000000 0000000 00000005260 14120400617 0017730 0 ustar 00root root 0000000 0000000 name: Main
on:
push:
branches:
- master
pull_request:
env:
GO_VERSION: 1.17
GOLANGCI_LINT_VERSION: v1.41.1
jobs:
linting:
name: Linting
runs-on: ubuntu-latest
steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check and get dependencies
run: |
go mod tidy
git diff --exit-code go.mod
# git diff --exit-code go.sum
go mod download
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
- name: Run golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
run: make check
generate:
name: Checks code and generated code
runs-on: ubuntu-latest
needs: linting
strategy:
matrix:
go-version: [ 1.16, 1.17 ]
steps:
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check generated code
run: |
rm -f interp/op.go
make generate
git update-index -q --refresh
CHANGED=$(git diff-index --name-only HEAD --)
test -z "$CHANGED" || echo $CHANGED
test -z "$CHANGED"
main:
name: Build and Test
runs-on: ubuntu-latest
needs: linting
defaults:
run:
working-directory: ${{ github.workspace }}/go/src/github.com/traefik/yaegi
strategy:
matrix:
go-version: [ 1.16, 1.17 ]
steps:
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Check out code
uses: actions/checkout@v2
with:
path: go/src/github.com/traefik/yaegi
fetch-depth: 0
# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v2
with:
path: ./_test/tmp
key: ${{ runner.os }}-yaegi-${{ hashFiles('**//_test/tmp/') }}
restore-keys: |
${{ runner.os }}-yaegi-
- name: Setup GOPATH
run: go env -w GOPATH=${{ github.workspace }}/go
- name: Build
run: go build -v ./...
- name: Run tests
run: make tests
env:
GOPATH: ${{ github.workspace }}/go
yaegi-0.10.0/.github/workflows/release.yml 0000664 0000000 0000000 00000001532 14120400617 0020422 0 ustar 00root root 0000000 0000000 name: Release
on:
push:
tags:
- v[0-9]+.[0-9]+*
env:
GO_VERSION: 1.17
jobs:
release:
name: Create a release
runs-on: ubuntu-latest
steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }}
yaegi-0.10.0/.gitignore 0000664 0000000 0000000 00000000154 14120400617 0014651 0 ustar 00root root 0000000 0000000 .*.swo
.*.swp
*.dot
.idea/
/yaegi
internal/cmd/extract/extract
example/inception/inception
_test/tmp/
/dist
yaegi-0.10.0/.golangci.toml 0000664 0000000 0000000 00000003010 14120400617 0015411 0 ustar 00root root 0000000 0000000 [run]
deadline = "5m"
skip-files = []
[linters-settings]
[linters-settings.govet]
check-shadowing = false
[linters-settings.gocyclo]
min-complexity = 12.0
[linters-settings.maligned]
suggest-new = true
[linters-settings.goconst]
min-len = 3.0
min-occurrences = 3.0
[linters-settings.misspell]
locale = "US"
[linters]
enable-all = true
disable = [
"golint", # deprecated
"scopelint", # deprecated
"interfacer", # deprecated
"maligned", # deprecated
"lll",
"gas",
"dupl",
"prealloc",
"gocyclo",
"cyclop",
"gochecknoinits",
"gochecknoglobals",
"wsl",
"nlreturn",
"godox",
"funlen",
"gocognit",
"stylecheck",
"gomnd",
"testpackage",
"paralleltest",
"tparallel",
"goerr113",
"wrapcheck",
"nestif",
"exhaustive",
"exhaustivestruct",
"forbidigo",
"ifshort",
"forcetypeassert",
"errorlint", # TODO: must be reactivate before fixes
]
[issues]
exclude-use-default = false
max-per-linter = 0
max-same-issues = 0
exclude = []
[[issues.exclude-rules]]
path = ".+_test\\.go"
linters = ["goconst"]
[[issues.exclude-rules]]
path = ".+_test\\.go"
text = "var-declaration:"
[[issues.exclude-rules]]
path = "interp/interp.go"
text = "`in` can be `io.Reader`"
[[issues.exclude-rules]]
path = "interp/interp.go"
text = "`out` can be `io.Writer`"
[[issues.exclude-rules]]
path = "interp/interp_eval_test.go"
linters = ["thelper"]
yaegi-0.10.0/.goreleaser.yml 0000664 0000000 0000000 00000002263 14120400617 0015615 0 ustar 00root root 0000000 0000000 project_name: yaegi
builds:
- id: yaegi
binary: yaegi
main: ./cmd/yaegi/
goos:
- darwin
- linux
# - windows
- freebsd
- openbsd
- solaris
goarch:
- amd64
- 386
- arm
- arm64
goarm:
- 7
- 6
- 5
ignore:
- goos: darwin
goarch: 386
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^doc:'
- '^chore:'
- '^test:'
- '^tests:'
archives:
- id: archive
name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
format: tar.gz
format_overrides:
- goos: windows
format: zip
files:
- LICENSE
brews:
- tap:
owner: traefik
name: homebrew-tap
commit_author:
name: traefiker
email: 30906710+traefiker@users.noreply.github.com
folder: Formula
homepage: https://github.com/traefik/yaegi
description: |
Yaegi is Another Elegant Go Interpreter.
It powers executable Go scripts and plugins, in embedded interpreters
or interactive shells, on top of the Go runtime.
test: |
system "#{bin}/yaegi version"
yaegi-0.10.0/CONTRIBUTING.md 0000664 0000000 0000000 00000002221 14120400617 0015107 0 ustar 00root root 0000000 0000000 # Contributing
Yaegi is an open source project, and your feedback and contributions
are needed and always welcome.
[Issues] and [Pull Requests] are opened at https://github.com/traefik/yaegi.
Non trivial changes should be discussed with the project maintainers by
opening a [Feature Request] clearly explaining rationale, background
and possible implementation ideas. Feel free to provide code in such
discussions.
Once the proposal is approved, a Pull Request can be opened. If you want
to provide early visibility to reviewers, create a [Draft Pull Request].
We will also require you to sign the [Traefik Contributor License Agreement]
after you submit your first pull request to this project. The link to sign the
agreement will be presented to you in the web interface of the pull request.
[Issues]: https://github.com/traefik/yaegi/issues
[Pull Requests]: https://github.com/traefik/yaegi/issues
[Feature Request]: https://github.com/traefik/yaegi/issues/new?template=feature_request.md
[Draft Pull Request]: https://github.blog/2019-02-14-introducing-draft-pull-requests/
[Traefik Labs Contributor License Agreement]: https://cla-assistant.io/traefik/yaegi
yaegi-0.10.0/LICENSE 0000664 0000000 0000000 00000026163 14120400617 0013676 0 ustar 00root root 0000000 0000000 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2019 Containous SAS
Copyright 2020 Traefik Labs SAS
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
yaegi-0.10.0/Makefile 0000664 0000000 0000000 00000001572 14120400617 0014326 0 ustar 00root root 0000000 0000000 # Static linting of source files. See .golangci.toml for options
check:
golangci-lint run
# Generate stdlib/syscall/syscall_GOOS_GOARCH.go for all platforms
gen_all_syscall: internal/cmd/extract/extract
@for v in $$(go tool dist list); do \
echo syscall_$${v%/*}_$${v#*/}.go; \
GOOS=$${v%/*} GOARCH=$${v#*/} go generate ./stdlib/syscall ./stdlib/unrestricted; \
done
internal/cmd/extract/extract:
rm -f internal/cmd/extract/extract
go generate ./internal/cmd/extract
generate: gen_all_syscall
go generate
install:
GOFLAGS=-ldflags=-X=main.version=$$(git describe --tags) go install ./...
tests:
go test -v ./...
go test -race ./interp
# https://github.com/goreleaser/godownloader
install.sh: .goreleaser.yml
godownloader --repo=traefik/yaegi -o install.sh .goreleaser.yml
.PHONY: check gen_all_syscall gen_tests generate_downloader internal/cmd/extract/extract install
yaegi-0.10.0/README.md 0000664 0000000 0000000 00000011740 14120400617 0014143 0 ustar 00root root 0000000 0000000
[](https://github.com/traefik/yaegi/releases)
[](https://github.com/traefik/yaegi/actions/workflows/main.yml)
[](https://pkg.go.dev/mod/github.com/traefik/yaegi)
[](https://community.traefik.io/c/yaegi)
Yaegi is Another Elegant Go Interpreter.
It powers executable Go scripts and plugins, in embedded interpreters or interactive shells, on top of the Go runtime.
## Features
* Complete support of [Go specification][specs]
* Written in pure Go, using only the standard library
* Simple interpreter API: `New()`, `Eval()`, `Use()`
* Works everywhere Go works
* All Go & runtime resources accessible from script (with control)
* Security: `unsafe` and `syscall` packages neither used nor exported by default
* Support Go 1.16 and Go 1.17 (the latest 2 major releases)
## Install
### Go package
```go
import "github.com/traefik/yaegi/interp"
```
### Command-line executable
```bash
go get -u github.com/traefik/yaegi/cmd/yaegi
```
Note that you can use [rlwrap](https://github.com/hanslub42/rlwrap) (install with your favorite package manager),
and alias the `yaegi` command in `alias yaegi='rlwrap yaegi'` in your `~/.bashrc`, to have history and command line edition.
### CI Integration
```bash
curl -sfL https://raw.githubusercontent.com/traefik/yaegi/master/install.sh | bash -s -- -b $GOPATH/bin v0.9.0
```
## Usage
### As an embedded interpreter
Create an interpreter with `New()`, run Go code with `Eval()`:
```go
package main
import (
"github.com/traefik/yaegi/interp"
"github.com/traefik/yaegi/stdlib"
)
func main() {
i := interp.New(interp.Options{})
i.Use(stdlib.Symbols)
_, err := i.Eval(`import "fmt"`)
if err != nil {
panic(err)
}
_, err = i.Eval(`fmt.Println("Hello Yaegi")`)
if err != nil {
panic(err)
}
}
```
[Go Playground](https://play.golang.org/p/2n-EpZbMYI9)
### As a dynamic extension framework
The following program is compiled ahead of time, except `bar()` which is interpreted, with the following steps:
1. use of `i.Eval(src)` to evaluate the script in the context of interpreter
2. use of `v, err := i.Eval("foo.Bar")` to get the symbol from the interpreter context, as a `reflect.Value`
3. application of `Interface()` method and type assertion to convert `v` into `bar`, as if it was compiled
```go
package main
import "github.com/traefik/yaegi/interp"
const src = `package foo
func Bar(s string) string { return s + "-Foo" }`
func main() {
i := interp.New(interp.Options{})
_, err := i.Eval(src)
if err != nil {
panic(err)
}
v, err := i.Eval("foo.Bar")
if err != nil {
panic(err)
}
bar := v.Interface().(func(string) string)
r := bar("Kung")
println(r)
}
```
[Go Playground](https://play.golang.org/p/WvwH4JqrU-p)
### As a command-line interpreter
The Yaegi command can run an interactive Read-Eval-Print-Loop:
```console
$ yaegi
> 1 + 2
3
> import "fmt"
> fmt.Println("Hello World")
Hello World
>
```
Note that in interactive mode, all stdlib package are pre-imported,
you can use them directly:
```console
$ yaegi
> reflect.TypeOf(time.Date)
: func(int, time.Month, int, int, int, int, int, *time.Location) time.Time
>
```
Or interpret Go packages, directories or files, including itself:
```console
$ yaegi -syscall -unsafe -unrestricted github.com/traefik/yaegi/cmd/yaegi
>
```
Or for Go scripting in the shebang line:
```console
$ cat /tmp/test
#!/usr/bin/env yaegi
package main
import "fmt"
func main() {
fmt.Println("test")
}
$ ls -la /tmp/test
-rwxr-xr-x 1 dow184 dow184 93 Jan 6 13:38 /tmp/test
$ /tmp/test
test
```
## Documentation
Documentation about Yaegi commands and libraries can be found at usual [godoc.org][docs].
## Limitations
Beside the known [bugs] which are supposed to be fixed in the short term, there are some limitations not planned to be addressed soon:
- Assembly files (`.s`) are not supported.
- Calling C code is not supported (no virtual "C" package).
- Interfaces to be used from the pre-compiled code can not be added dynamically, as it is required to pre-compile interface wrappers.
- Representation of types by `reflect` and printing values using %T may give different results between compiled mode and interpreted mode.
- Interpreting computation intensive code is likely to remain significantly slower than in compiled mode.
## Contributing
[Contributing guide](CONTRIBUTING.md).
## License
[Apache 2.0][License].
[specs]: https://golang.org/ref/spec
[docs]: https://pkg.go.dev/github.com/traefik/yaegi
[license]: https://github.com/traefik/yaegi/blob/master/LICENSE
[github]: https://github.com/traefik/yaegi
[bugs]: https://github.com/traefik/yaegi/issues?q=is%3Aissue+is%3Aopen+label%3Abug
yaegi-0.10.0/_test/ 0000775 0000000 0000000 00000000000 14120400617 0013777 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/a1.go 0000664 0000000 0000000 00000000270 14120400617 0014626 0 ustar 00root root 0000000 0000000 package main
func main() {
a := [6]int{1, 2, 3, 4, 5, 6}
println(a[1]) // 2
for i, v := range a {
println(v)
if i == 3 {
break
}
}
}
// Output:
// 2
// 1
// 2
// 3
// 4
yaegi-0.10.0/_test/a10.go 0000664 0000000 0000000 00000000325 14120400617 0014707 0 ustar 00root root 0000000 0000000 package main
type Sample struct {
Name string
}
var samples = []Sample{}
func f(i int) {
println(samples[i].Name)
}
func main() {
samples = append(samples, Sample{Name: "test"})
f(0)
}
// Output:
// test
yaegi-0.10.0/_test/a11.go 0000664 0000000 0000000 00000000175 14120400617 0014713 0 ustar 00root root 0000000 0000000 package main
func main() {
a := []int{1, 2, 3, 4}
for _, v := range a {
println(v)
}
}
// Output:
// 1
// 2
// 3
// 4
yaegi-0.10.0/_test/a12.go 0000664 0000000 0000000 00000000143 14120400617 0014707 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var buf [12]int
fmt.Println(buf[0])
}
// Output:
// 0
yaegi-0.10.0/_test/a13.go 0000664 0000000 0000000 00000000245 14120400617 0014713 0 ustar 00root root 0000000 0000000 package main
type T1 struct {
num []int
}
func main() {
a := T1{[]int{1, 3, 5}}
for i, v := range a.num {
println(i, v)
}
}
// Output:
// 0 1
// 1 3
// 2 5
yaegi-0.10.0/_test/a14.go 0000664 0000000 0000000 00000000213 14120400617 0014707 0 ustar 00root root 0000000 0000000 package main
import "fmt"
const size = 12
func main() {
var buf [size]int
fmt.Println(buf)
}
// Output:
// [0 0 0 0 0 0 0 0 0 0 0 0]
yaegi-0.10.0/_test/a15.go 0000664 0000000 0000000 00000000216 14120400617 0014713 0 ustar 00root root 0000000 0000000 package main
import "fmt"
const size = 12
func main() {
var buf [size]int
fmt.Println(buf[:])
}
// Output:
// [0 0 0 0 0 0 0 0 0 0 0 0]
yaegi-0.10.0/_test/a16.go 0000664 0000000 0000000 00000000357 14120400617 0014722 0 ustar 00root root 0000000 0000000 package main
func main() {
a := [6]int{1, 2, 3, 4, 5, 6}
println(a[1]) // 2
for k := 0; k < 2; k++ {
for i, v := range a {
println(v)
if i == 3 {
break
}
}
}
}
// Output:
// 2
// 1
// 2
// 3
// 4
// 1
// 2
// 3
// 4
yaegi-0.10.0/_test/a17.go 0000664 0000000 0000000 00000000175 14120400617 0014721 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := make([]int, 2, 7)
fmt.Println(a, len(a), cap(a))
}
// Output:
// [0 0] 2 7
yaegi-0.10.0/_test/a18.go 0000664 0000000 0000000 00000000177 14120400617 0014724 0 ustar 00root root 0000000 0000000 package main
func main() {
a := []int64{1, 2, 3, 4}
for _, v := range a {
println(v)
}
}
// Output:
// 1
// 2
// 3
// 4
yaegi-0.10.0/_test/a19.go 0000664 0000000 0000000 00000000152 14120400617 0014716 0 ustar 00root root 0000000 0000000 package main
func main() {
var buf [bsize]byte
println(len(buf))
}
const bsize = 10
// Output:
// 10
yaegi-0.10.0/_test/a2.go 0000664 0000000 0000000 00000000302 14120400617 0014623 0 ustar 00root root 0000000 0000000 package main
func main() {
a := [6]int{1, 2, 3, 4, 5, 6}
a[1] = 5
println(a[1]) // 2
for i, v := range a {
println(v)
if i == 3 {
break
}
}
}
// Output:
// 5
// 1
// 5
// 3
// 4
yaegi-0.10.0/_test/a20.go 0000664 0000000 0000000 00000000267 14120400617 0014715 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type IntArray []int
func (h *IntArray) Add(x int) {
*h = append(*h, x)
}
func main() {
a := IntArray{}
a.Add(4)
fmt.Println(a)
}
// Output:
// [4]
yaegi-0.10.0/_test/a21.go 0000664 0000000 0000000 00000000267 14120400617 0014716 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := []byte("hello")
fmt.Println(a)
a = append(a, '=')
fmt.Println(a)
}
// Output:
// [104 101 108 108 111]
// [104 101 108 108 111 61]
yaegi-0.10.0/_test/a22.go 0000664 0000000 0000000 00000000153 14120400617 0014711 0 ustar 00root root 0000000 0000000 package main
func main() {
a := [256]int{}
var b uint8 = 12
a[b] = 1
println(a[b])
}
// Output:
// 1
yaegi-0.10.0/_test/a23.go 0000664 0000000 0000000 00000000572 14120400617 0014717 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var key, salt [32]byte
for i := range key {
key[i] = byte(i)
salt[i] = byte(i + 32)
}
fmt.Println(key)
fmt.Println(salt)
}
// Output:
// [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31]
// [32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63]
yaegi-0.10.0/_test/a24.go 0000664 0000000 0000000 00000000463 14120400617 0014717 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
for i := 0; i < 2; i++ {
var buf [8]byte
var x int
fmt.Println(buf, x)
for i := range buf {
buf[i] = byte(i)
x = i
}
fmt.Println(buf, x)
}
}
// Output:
// [0 0 0 0 0 0 0 0] 0
// [0 1 2 3 4 5 6 7] 7
// [0 0 0 0 0 0 0 0] 0
// [0 1 2 3 4 5 6 7] 7
yaegi-0.10.0/_test/a25.go 0000664 0000000 0000000 00000000326 14120400617 0014716 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var buf [8]byte
for i := 0; i < 2; i++ {
for i := range buf {
buf[i] += byte(i)
}
fmt.Println(buf)
}
}
// Output:
// [0 1 2 3 4 5 6 7]
// [0 2 4 6 8 10 12 14]
yaegi-0.10.0/_test/a26.go 0000664 0000000 0000000 00000000157 14120400617 0014721 0 ustar 00root root 0000000 0000000 package main
func main() {
a := [3]int{1, 2, 3}
b := [3]int{1, 2, 3}
println(a == b)
}
// Output:
// true
yaegi-0.10.0/_test/a27.go 0000664 0000000 0000000 00000000224 14120400617 0014715 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [...]string{"hello", "world"}
fmt.Printf("%v %T\n", a, a)
}
// Output:
// [hello world] [2]string
yaegi-0.10.0/_test/a28.go 0000664 0000000 0000000 00000000222 14120400617 0014714 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [...]string{9: "hello"}
fmt.Printf("%v %T\n", a, a)
}
// Output:
// [ hello] [10]string
yaegi-0.10.0/_test/a29.go 0000664 0000000 0000000 00000000327 14120400617 0014723 0 ustar 00root root 0000000 0000000 package main
import "fmt"
const (
zero = iota
one
two
)
func main() {
a := [...]string{
zero: "zero",
one: "one",
two: "two",
}
fmt.Printf("%v %T\n", a, a)
}
// Output:
// [zero one two] [3]string
yaegi-0.10.0/_test/a3.go 0000664 0000000 0000000 00000000170 14120400617 0014627 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [6]int{1, 2, 3, 4, 5, 6}
fmt.Println(a[2:])
}
// Output:
// [3 4 5 6]
yaegi-0.10.0/_test/a30.go 0000664 0000000 0000000 00000000134 14120400617 0014707 0 ustar 00root root 0000000 0000000 package main
func main() {
for range []struct{}{} {
}
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/a31.go 0000664 0000000 0000000 00000000175 14120400617 0014715 0 ustar 00root root 0000000 0000000 package main
func main() {
for range []int{0, 1, 2} {
print("hello ")
}
println("")
}
// Output:
// hello hello hello
yaegi-0.10.0/_test/a32.go 0000664 0000000 0000000 00000000162 14120400617 0014712 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T struct{}
var a = []T{{}}
func main() {
fmt.Println(a)
}
// Output:
// [{}]
yaegi-0.10.0/_test/a33.go 0000664 0000000 0000000 00000000163 14120400617 0014714 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [...]int{1, 2, 3}
b := a
fmt.Println(b)
}
// Output:
// [1 2 3]
yaegi-0.10.0/_test/a34.go 0000664 0000000 0000000 00000000175 14120400617 0014720 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [...]int{1, 2, 3}
var b [3]int = a
fmt.Println(b)
}
// Output:
// [1 2 3]
yaegi-0.10.0/_test/a35.go 0000664 0000000 0000000 00000000176 14120400617 0014722 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [...]int{1, 2, 3}
b := a
b[0] = -1
fmt.Println(a)
}
// Output:
// [1 2 3]
yaegi-0.10.0/_test/a36.go 0000664 0000000 0000000 00000000210 14120400617 0014710 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [...]int{1, 2, 3}
var b [3]int = a
b[0] = -1
fmt.Println(a)
}
// Output:
// [1 2 3]
yaegi-0.10.0/_test/a37.go 0000664 0000000 0000000 00000000153 14120400617 0014717 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [...]int{1, 2, 3}
fmt.Println(a)
}
// Output:
// [1 2 3]
yaegi-0.10.0/_test/a38.go 0000664 0000000 0000000 00000000155 14120400617 0014722 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [...]byte{}
fmt.Printf("%T\n", a)
}
// Output:
// [0]uint8
yaegi-0.10.0/_test/a39.go 0000664 0000000 0000000 00000000204 14120400617 0014716 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [...]byte{}
b := a
fmt.Printf("%T %T\n", a, b)
}
// Output:
// [0]uint8 [0]uint8
yaegi-0.10.0/_test/a4.go 0000664 0000000 0000000 00000000165 14120400617 0014634 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [6]int{1, 2, 3, 4, 5, 6}
fmt.Println(a[2:4])
}
// Output:
// [3 4]
yaegi-0.10.0/_test/a40.go 0000664 0000000 0000000 00000000254 14120400617 0014713 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type rule uint8
const (
r0 rule = iota
r1
r2
)
var a = [...]int{
r0: 1,
r1: 12,
}
func main() {
fmt.Println(a)
}
// Output:
// [1 12]
yaegi-0.10.0/_test/a41.go 0000664 0000000 0000000 00000000150 14120400617 0014707 0 ustar 00root root 0000000 0000000 package main
var a = [...]bool{true, true}
func main() {
println(a[0] && true)
}
// Output:
// true
yaegi-0.10.0/_test/a42.go 0000664 0000000 0000000 00000000265 14120400617 0014717 0 ustar 00root root 0000000 0000000 package main
import (
"encoding/binary"
"fmt"
)
func main() {
var b [8]byte
binary.LittleEndian.PutUint64(b[:], uint64(1))
fmt.Println(b)
}
// Output:
// [1 0 0 0 0 0 0 0]
yaegi-0.10.0/_test/a43.go 0000664 0000000 0000000 00000000211 14120400617 0014707 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T [l1 + l2]int
const (
l1 = 2
l2 = 3
)
func main() {
fmt.Println(T{})
}
// Output:
// [0 0 0 0 0]
yaegi-0.10.0/_test/a44.go 0000664 0000000 0000000 00000000145 14120400617 0014716 0 ustar 00root root 0000000 0000000 package main
var a = [max]int{}
const max = 32
func main() {
println(len(a))
}
// Output:
// 32
yaegi-0.10.0/_test/a5.go 0000664 0000000 0000000 00000000170 14120400617 0014631 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [6]int{1, 2, 3, 4, 5, 6}
fmt.Println(a[:4])
}
// Output:
// [1 2 3 4]
yaegi-0.10.0/_test/a6.go 0000664 0000000 0000000 00000000173 14120400617 0014635 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [6]int{1, 2, 3, 4, 5, 6}
fmt.Println(a[:])
}
// Output:
// [1 2 3 4 5 6]
yaegi-0.10.0/_test/a7.go 0000664 0000000 0000000 00000000161 14120400617 0014633 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [6]int{1, 2, 3, 4, 5, 6}
fmt.Println(len(a))
}
// Output:
// 6
yaegi-0.10.0/_test/a8.go 0000664 0000000 0000000 00000000222 14120400617 0014632 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
//a := []int{1, 2}
a := make([]int, 2)
//a[0] = 1
//a[1] = 2
fmt.Println(a)
}
// Output:
// [0 0]
yaegi-0.10.0/_test/a9.go 0000664 0000000 0000000 00000000273 14120400617 0014641 0 ustar 00root root 0000000 0000000 package main
import "fmt"
//var (
// samples = []int{}
// b = 1
//)
func main() {
var samples = []int{}
samples = append(samples, 1)
fmt.Println(samples)
}
// Output:
// [1]
yaegi-0.10.0/_test/add0.go 0000664 0000000 0000000 00000000134 14120400617 0015134 0 ustar 00root root 0000000 0000000 package main
func main() {
var a interface{} = 2 + 5
println(a.(int))
}
// Output:
// 7
yaegi-0.10.0/_test/add1.go 0000664 0000000 0000000 00000000740 14120400617 0015140 0 ustar 00root root 0000000 0000000 package main
func main() {
b := 2 // int
var c int = 5 + b
println(c)
var d int32 = 6 + int32(b)
println(d)
var a interface{} = 7 + b
println(a.(int))
var e int32 = 2
var f interface{} = 8 + e
println(f.(int32))
a = 9 + e
println(a.(int32))
var g int = 2
a = 10 + g
println(a.(int))
// multiple assignment
var foo interface{}
foo, a = "hello", 11 + g
println(a.(int))
println(foo.(string))
}
// Output:
// 7
// 8
// 9
// 10
// 11
// 12
// 13
// hello
yaegi-0.10.0/_test/add2.go 0000664 0000000 0000000 00000000166 14120400617 0015143 0 ustar 00root root 0000000 0000000 package main
type iface interface{}
func main() {
b := 2
var a iface = 5 + b
println(a.(int))
}
// Output:
// 7
yaegi-0.10.0/_test/addr0.go 0000664 0000000 0000000 00000000633 14120400617 0015322 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
type extendedRequest struct {
http.Request
Data string
}
func main() {
r := extendedRequest{}
req := &r.Request
fmt.Println(r)
fmt.Println(req)
}
// Output:
// {{ 0 0 map[] 0 [] false map[] map[] map[] } }
// &{ 0 0 map[] 0 [] false map[] map[] map[] }
yaegi-0.10.0/_test/addr1.go 0000664 0000000 0000000 00000000335 14120400617 0015322 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T struct {
A int
B int
}
func main() {
a := &[]T{
{1, 2},
{3, 4},
}
fmt.Println("a:", a)
x := &(*a)[1:][0]
fmt.Println("x:", x)
}
// Output:
// a: &[{1 2} {3 4}]
// x: &{3 4}
yaegi-0.10.0/_test/addr2.go 0000664 0000000 0000000 00000002016 14120400617 0015321 0 ustar 00root root 0000000 0000000 package main
import (
"encoding/xml"
"errors"
"fmt"
)
type Email struct {
Where string `xml:"where,attr"`
Addr string
}
func f(r interface{}) error {
return withPointerAsInterface(&r)
}
func withPointerAsInterface(r interface{}) error {
_ = (r).(*interface{})
rp, ok := (r).(*interface{})
if !ok {
return errors.New("cannot assert to *interface{}")
}
em, ok := (*rp).(*Email)
if !ok {
return errors.New("cannot assert to *Email")
}
em.Where = "work"
em.Addr = "bob@work.com"
return nil
}
func ff(s string, r interface{}) error {
return xml.Unmarshal([]byte(s), r)
}
func fff(s string, r interface{}) error {
return xml.Unmarshal([]byte(s), &r)
}
func main() {
data := `
bob@work.com
`
v := Email{}
err := f(&v)
fmt.Println(err, v)
vv := Email{}
err = ff(data, &vv)
fmt.Println(err, vv)
vvv := Email{}
err = ff(data, &vvv)
fmt.Println(err, vvv)
}
// Output:
// {work bob@work.com}
// {work bob@work.com}
// {work bob@work.com}
yaegi-0.10.0/_test/addr3.go 0000664 0000000 0000000 00000000324 14120400617 0015322 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
func main() {
var a interface{}
a = 2
fmt.Println(a)
var b *interface{}
b = &a
fmt.Println(*b)
var c **interface{}
c = &b
fmt.Println(**c)
}
// Output:
// 2
// 2
// 2
yaegi-0.10.0/_test/addr4.go 0000664 0000000 0000000 00000003004 14120400617 0015321 0 ustar 00root root 0000000 0000000 package main
import (
"encoding/json"
"fmt"
"log"
)
const jsonData = `[
"foo",
"bar"
]`
const jsonData2 = `[
{"foo": "foo"},
{"bar": "bar"}
]`
const jsonData3 = `{
"foo": "foo",
"bar": "bar"
}`
func fromSlice() {
var a []interface{}
var c, d interface{}
c = 2
d = 3
a = []interface{}{c, d}
if err := json.Unmarshal([]byte(jsonData), &a); err != nil {
log.Fatalln(err)
}
for k, v := range a {
fmt.Println(k, ":", v)
}
}
func fromEmpty() {
var a interface{}
var c, d interface{}
c = 2
d = 3
a = []interface{}{c, d}
if err := json.Unmarshal([]byte(jsonData), &a); err != nil {
log.Fatalln(err)
}
b := a.([]interface{})
for k, v := range b {
fmt.Println(k, ":", v)
}
}
func sliceOfObjects() {
var a interface{}
if err := json.Unmarshal([]byte(jsonData2), &a); err != nil {
log.Fatalln(err)
}
b := a.([]interface{})
for k, v := range b {
fmt.Println(k, ":", v)
}
}
func intoMap() {
var a interface{}
if err := json.Unmarshal([]byte(jsonData3), &a); err != nil {
log.Fatalln(err)
}
b := a.(map[string]interface{})
seenFoo := false
for k, v := range b {
vv := v.(string)
if vv != "foo" {
if seenFoo {
fmt.Println(k, ":", vv)
break
}
kk := k
vvv := vv
defer fmt.Println(kk, ":", vvv)
continue
}
seenFoo = true
fmt.Println(k, ":", vv)
}
}
func main() {
fromSlice()
fromEmpty()
sliceOfObjects()
intoMap()
}
// Output:
// 0 : foo
// 1 : bar
// 0 : foo
// 1 : bar
// 0 : map[foo:foo]
// 1 : map[bar:bar]
// foo : foo
// bar : bar
yaegi-0.10.0/_test/addr5.go 0000664 0000000 0000000 00000002155 14120400617 0015330 0 ustar 00root root 0000000 0000000 package main
import (
"encoding/json"
"fmt"
"net/url"
)
func main() {
body := []byte(`{
"BODY_1": "VALUE_1",
"BODY_2": "VALUE_2",
"BODY_3": null,
"BODY_4": {
"BODY_1": "VALUE_1",
"BODY_2": "VALUE_2",
"BODY_3": null
},
"BODY_5": [
"VALUE_1",
"VALUE_2",
"VALUE_3"
]
}`)
values := url.Values{}
var rawData map[string]interface{}
err := json.Unmarshal(body, &rawData)
if err != nil {
fmt.Println("can't parse body")
return
}
for key, val := range rawData {
switch val.(type) {
case string, bool, float64:
values.Add(key, fmt.Sprint(val))
case nil:
values.Add(key, "")
case map[string]interface{}, []interface{}:
jsonVal, err := json.Marshal(val)
if err != nil {
fmt.Println("can't encode json")
return
}
values.Add(key, string(jsonVal))
}
}
fmt.Println(values.Get("BODY_1"))
fmt.Println(values.Get("BODY_2"))
fmt.Println(values.Get("BODY_3"))
fmt.Println(values.Get("BODY_4"))
fmt.Println(values.Get("BODY_5"))
}
// Output:
// VALUE_1
// VALUE_2
//
// {"BODY_1":"VALUE_1","BODY_2":"VALUE_2","BODY_3":null}
// ["VALUE_1","VALUE_2","VALUE_3"]
yaegi-0.10.0/_test/alias0.go 0000664 0000000 0000000 00000000664 14120400617 0015505 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type Root struct {
Name string
}
func (r *Root) Hello() {
fmt.Println("Hello", r.Name)
}
type One = Root
func main() {
one := &One{Name: "one"}
displayOne(one)
displayRoot(one)
root := &Root{Name: "root"}
displayOne(root)
displayRoot(root)
}
func displayOne(val *One) {
fmt.Println(val)
}
func displayRoot(val *Root) {
fmt.Println(val)
}
// Output:
// &{one}
// &{one}
// &{root}
// &{root}
yaegi-0.10.0/_test/alias1.go 0000664 0000000 0000000 00000000176 14120400617 0015504 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type MyT T
type T struct {
Name string
}
func main() {
fmt.Println(MyT{})
}
// Output:
// {}
yaegi-0.10.0/_test/alias2.go 0000664 0000000 0000000 00000000244 14120400617 0015501 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func (t MyT) Test() string {
return "hello"
}
type MyT int
func main() {
t := MyT(1)
fmt.Println(t.Test())
}
// Output:
// hello
yaegi-0.10.0/_test/alias3.go 0000664 0000000 0000000 00000000361 14120400617 0015502 0 ustar 00root root 0000000 0000000 package main
import "github.com/traefik/yaegi/_test/alias3"
var globalT *T
func init() {
globalT = &T{A: "test"}
}
type T alias3.T
func (t *T) PrintT() {
(*alias3.T)(t).Print()
}
func main() {
globalT.PrintT()
}
// Output:
// test
yaegi-0.10.0/_test/alias3/ 0000775 0000000 0000000 00000000000 14120400617 0015153 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/alias3/alias3.go 0000664 0000000 0000000 00000000123 14120400617 0016652 0 ustar 00root root 0000000 0000000 package alias3
type T struct {
A string
}
func (t *T) Print() {
println(t.A)
}
yaegi-0.10.0/_test/and.go 0000664 0000000 0000000 00000000356 14120400617 0015074 0 ustar 00root root 0000000 0000000 package main
func main() {
a, b := 1, 2
if f1() && f2() {
println(a, b)
}
}
func f1() bool {
println("f1")
//return true
return 0 == 0
}
func f2() bool {
println("f2")
//return false
return 1 == 0
}
// Output:
// f1
// f2
yaegi-0.10.0/_test/and0.go 0000664 0000000 0000000 00000000306 14120400617 0015147 0 ustar 00root root 0000000 0000000 package main
func main() {
a, b := 1, 2
if f2() && f1() {
println(a, b)
}
}
func f1() bool {
println("f1")
return true
}
func f2() bool {
println("f2")
return false
}
// Output:
// f2
yaegi-0.10.0/_test/and1.go 0000664 0000000 0000000 00000000271 14120400617 0015151 0 ustar 00root root 0000000 0000000 package main
func main() {
a := f2() && f1()
println(a)
}
func f1() bool {
println("f1")
return true
}
func f2() bool {
println("f2")
return false
}
// Output:
// f2
// false
yaegi-0.10.0/_test/and2.go 0000664 0000000 0000000 00000000352 14120400617 0015152 0 ustar 00root root 0000000 0000000 package main
func f() bool {
println("in f")
return true
}
func main() {
var (
cl = 0
ct = "some text"
ce = ""
)
if ce == "" && (cl == 0 || cl > 1000) && (ct == "" || f()) {
println("ok")
}
}
// Output:
// in f
// ok
yaegi-0.10.0/_test/and3.go 0000664 0000000 0000000 00000000124 14120400617 0015150 0 ustar 00root root 0000000 0000000 package main
var a = true && true
func main() {
println(a)
}
// Output:
// true
yaegi-0.10.0/_test/append0.go 0000664 0000000 0000000 00000000267 14120400617 0015662 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f(a []int, b int) interface{} { return append(a, b) }
func main() {
a := []int{1, 2}
r := f(a, 3)
fmt.Println(r.([]int))
}
// Output:
// [1 2 3]
yaegi-0.10.0/_test/append1.go 0000664 0000000 0000000 00000000340 14120400617 0015653 0 ustar 00root root 0000000 0000000 package main
import (
"bufio"
"bytes"
)
func main() {
s := bufio.NewScanner(bytes.NewReader([]byte("Hello\nTest\nLine3")))
s.Scan()
println(string(append(s.Bytes(), []byte(" World")...)))
}
// Output:
// Hello World
yaegi-0.10.0/_test/append2.go 0000664 0000000 0000000 00000000330 14120400617 0015653 0 ustar 00root root 0000000 0000000 package main
import (
"bufio"
"bytes"
)
func main() {
s := bufio.NewScanner(bytes.NewReader([]byte("Hello\nTest\nLine3")))
s.Scan()
println(string(append(s.Bytes(), " World"...)))
}
// Output:
// Hello World
yaegi-0.10.0/_test/append3.go 0000664 0000000 0000000 00000000300 14120400617 0015651 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := []int{1, 2}
b := [2]int{3, 4}
fmt.Println(append(a, b[:]...))
fmt.Println(append(a, []int{5, 6}...))
}
// Output:
// [1 2 3 4]
// [1 2 5 6]
yaegi-0.10.0/_test/append4.go 0000664 0000000 0000000 00000000166 14120400617 0015664 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := []*int{}
a = append(a, nil)
fmt.Println(a)
}
// Output:
// []
yaegi-0.10.0/_test/assert0.go 0000664 0000000 0000000 00000004712 14120400617 0015713 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
type MyWriter interface {
Write(p []byte) (i int, err error)
}
type DummyWriter interface {
Write(p []byte) (i int, err error)
}
type TestStruct struct{}
func (t TestStruct) Write(p []byte) (n int, err error) {
return len(p), nil
}
func usesWriter(w MyWriter) {
n, _ := w.Write([]byte("hello world"))
fmt.Println(n)
}
type MyStringer interface {
String() string
}
type DummyStringer interface {
String() string
}
func usesStringer(s MyStringer) {
fmt.Println(s.String())
}
func main() {
// TODO(mpl): restore when we can deal with empty interface.
// var t interface{}
var t DummyWriter
t = TestStruct{}
var tw MyWriter
var ok bool
tw, ok = t.(MyWriter)
if !ok {
fmt.Println("TestStruct does not implement MyWriter")
} else {
fmt.Println("TestStruct implements MyWriter")
usesWriter(tw)
}
n, _ := t.(MyWriter).Write([]byte("hello world"))
fmt.Println(n)
// not redundant with the above, because it goes through a slightly different code path.
if _, ok := t.(MyWriter); !ok {
fmt.Println("TestStruct does not implement MyWriter")
return
} else {
fmt.Println("TestStruct implements MyWriter")
}
// TODO(mpl): restore
/*
t = 42
foo, ok := t.(MyWriter)
if !ok {
fmt.Println("42 does not implement MyWriter")
} else {
fmt.Println("42 implements MyWriter")
}
_ = foo
if _, ok := t.(MyWriter); !ok {
fmt.Println("42 does not implement MyWriter")
} else {
fmt.Println("42 implements MyWriter")
}
*/
// var tt interface{}
var tt DummyStringer
tt = time.Nanosecond
var myD MyStringer
myD, ok = tt.(MyStringer)
if !ok {
fmt.Println("time.Nanosecond does not implement MyStringer")
} else {
fmt.Println("time.Nanosecond implements MyStringer")
usesStringer(myD)
}
fmt.Println(tt.(MyStringer).String())
if _, ok := tt.(MyStringer); !ok {
fmt.Println("time.Nanosecond does not implement MyStringer")
} else {
fmt.Println("time.Nanosecond implements MyStringer")
}
// TODO(mpl): restore
/*
tt = 42
bar, ok := tt.(MyStringer)
if !ok {
fmt.Println("42 does not implement MyStringer")
} else {
fmt.Println("42 implements MyStringer")
}
_ = bar
if _, ok := tt.(MyStringer); !ok {
fmt.Println("42 does not implement MyStringer")
} else {
fmt.Println("42 implements MyStringer")
}
*/
}
// Output:
// TestStruct implements MyWriter
// 11
// 11
// TestStruct implements MyWriter
// time.Nanosecond implements MyStringer
// 1ns
// 1ns
// time.Nanosecond implements MyStringer
yaegi-0.10.0/_test/assert1.go 0000664 0000000 0000000 00000003447 14120400617 0015720 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"reflect"
"time"
)
type TestStruct struct{}
func (t TestStruct) String() string {
return "hello world"
}
type DummyStringer interface{
String() string
}
func main() {
aType := reflect.TypeOf((*fmt.Stringer)(nil)).Elem()
var t interface{}
t = time.Nanosecond
s, ok := t.(fmt.Stringer)
if !ok {
fmt.Println("time.Nanosecond does not implement fmt.Stringer")
return
}
fmt.Println(s.String())
fmt.Println(t.(fmt.Stringer).String())
bType := reflect.TypeOf(time.Nanosecond)
fmt.Println(bType.Implements(aType))
// not redundant with the above, because it goes through a slightly different code path.
if _, ok := t.(fmt.Stringer); !ok {
fmt.Println("time.Nanosecond does not implement fmt.Stringer")
return
} else {
fmt.Println("time.Nanosecond implements fmt.Stringer")
}
t = 42
foo, ok := t.(fmt.Stringer)
if !ok {
fmt.Println("42 does not implement fmt.Stringer")
} else {
fmt.Println("42 implements fmt.Stringer")
return
}
_ = foo
if _, ok := t.(fmt.Stringer); !ok {
fmt.Println("42 does not implement fmt.Stringer")
} else {
fmt.Println("42 implements fmt.Stringer")
return
}
// TODO(mpl): restore when fixed
// var tt interface{}
var tt DummyStringer
tt = TestStruct{}
ss, ok := tt.(fmt.Stringer)
if !ok {
fmt.Println("TestStuct does not implement fmt.Stringer")
return
}
fmt.Println(ss.String())
fmt.Println(tt.(fmt.Stringer).String())
if _, ok := tt.(fmt.Stringer); !ok {
fmt.Println("TestStuct does not implement fmt.Stringer")
return
} else {
fmt.Println("TestStuct implements fmt.Stringer")
}
}
// Output:
// 1ns
// 1ns
// true
// time.Nanosecond implements fmt.Stringer
// 42 does not implement fmt.Stringer
// 42 does not implement fmt.Stringer
// hello world
// hello world
// TestStuct implements fmt.Stringer
yaegi-0.10.0/_test/assert2.go 0000664 0000000 0000000 00000001163 14120400617 0015712 0 ustar 00root root 0000000 0000000 package main
import (
"strings"
"sync"
)
// Defined an interface of stringBuilder that compatible with
// strings.Builder(go 1.10) and bytes.Buffer(< go 1.10)
type stringBuilder interface {
WriteRune(r rune) (n int, err error)
WriteString(s string) (int, error)
Reset()
Grow(n int)
String() string
}
var builderPool = sync.Pool{New: func() interface{} {
return newStringBuilder()
}}
func newStringBuilder() stringBuilder {
return &strings.Builder{}
}
func main() {
i := builderPool.Get()
sb := i.(stringBuilder)
_, _ = sb.WriteString("hello")
println(sb.String())
builderPool.Put(i)
}
// Output:
// hello
yaegi-0.10.0/_test/assign.go 0000664 0000000 0000000 00000000141 14120400617 0015606 0 ustar 00root root 0000000 0000000 package main
func main() {
a, b := 1, 2 // Multiple assign
println(a, b)
}
// Output:
// 1 2
yaegi-0.10.0/_test/assign0.go 0000664 0000000 0000000 00000000436 14120400617 0015675 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
"time"
)
func main() {
http.DefaultClient.Timeout = time.Second * 10
fmt.Println(http.DefaultClient)
http.DefaultClient = &http.Client{}
fmt.Println(http.DefaultClient)
}
// Output:
// &{ 10s}
// &{ 0s}
yaegi-0.10.0/_test/assign1.go 0000664 0000000 0000000 00000000154 14120400617 0015673 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var buf []byte
buf = nil
fmt.Println(buf)
}
// Output:
// []
yaegi-0.10.0/_test/assign10.go 0000664 0000000 0000000 00000000122 14120400617 0015746 0 ustar 00root root 0000000 0000000 package main
func main() {
var a uint
a = 1 + 2
println(a)
}
// Output:
// 3
yaegi-0.10.0/_test/assign11.go 0000664 0000000 0000000 00000000240 14120400617 0015750 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
_, _, _ = fmt.Println("test")
}
// Error:
// 6:2: assignment mismatch: 3 variables but fmt.Println returns 2 values
yaegi-0.10.0/_test/assign12.go 0000664 0000000 0000000 00000000263 14120400617 0015756 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a, b, c := fmt.Println("test")
println(a, b, c)
}
// Error:
// 6:2: assignment mismatch: 3 variables but fmt.Println returns 2 values
yaegi-0.10.0/_test/assign13.go 0000664 0000000 0000000 00000000413 14120400617 0015754 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func getStr() string {
return "test"
}
func main() {
m := make(map[string]string, 0)
m["a"] = fmt.Sprintf("%v", 0.1)
m["b"] = string(fmt.Sprintf("%v", 0.1))
m["c"] = getStr()
fmt.Println(m)
}
// Output:
// map[a:0.1 b:0.1 c:test]
yaegi-0.10.0/_test/assign14.go 0000664 0000000 0000000 00000000277 14120400617 0015765 0 ustar 00root root 0000000 0000000 package main
var optionsG map[string]string = nil
var roundG = 30
func main() {
dummy := roundG
roundG = dummy + 1
println(roundG)
println(optionsG == nil)
}
// Output:
// 31
// true
yaegi-0.10.0/_test/assign15.go 0000664 0000000 0000000 00000000334 14120400617 0015760 0 ustar 00root root 0000000 0000000 package main
func main() {
var c chan<- struct{} = make(chan struct{})
var d <-chan struct{} = c
_ = d
}
// Error:
// _test/assign15.go:5:26: cannot use type chan<- struct {} as type <-chan struct {} in assignment
yaegi-0.10.0/_test/assign16.go 0000664 0000000 0000000 00000000207 14120400617 0015760 0 ustar 00root root 0000000 0000000 package main
type H struct {
bits uint
}
func main() {
h := &H{8}
var x uint = (1 << h.bits) >> 6
println(x)
}
// Output:
// 4
yaegi-0.10.0/_test/assign2.go 0000664 0000000 0000000 00000000231 14120400617 0015670 0 ustar 00root root 0000000 0000000 package main
func main() {
r := uint32(2000000000)
r = hello(r)
println(r)
}
func hello(r uint32) uint32 { return r + 1 }
// Output:
// 2000000001
yaegi-0.10.0/_test/assign3.go 0000664 0000000 0000000 00000000161 14120400617 0015673 0 ustar 00root root 0000000 0000000 package main
func main() {
a, b := 1, 2
println(a, b)
a, b = b, a
println(a, b)
}
// Output:
// 1 2
// 2 1
yaegi-0.10.0/_test/assign4.go 0000664 0000000 0000000 00000000207 14120400617 0015675 0 ustar 00root root 0000000 0000000 package main
func main() {
a, b, c := 1, 2, 3
println(a, b, c)
a, b, c = c, a, b
println(a, b, c)
}
// Output:
// 1 2 3
// 3 1 2
yaegi-0.10.0/_test/assign5.go 0000664 0000000 0000000 00000000225 14120400617 0015676 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
t := []int{1, 2}
fmt.Println(t)
t[0], t[1] = t[1], t[0]
fmt.Println(t)
}
// Output:
// [1 2]
// [2 1]
yaegi-0.10.0/_test/assign6.go 0000664 0000000 0000000 00000000306 14120400617 0015677 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
t := map[string]int{"a": 1, "b": 2}
fmt.Println(t["a"], t["b"])
t["a"], t["b"] = t["b"], t["a"]
fmt.Println(t["a"], t["b"])
}
// Output:
// 1 2
// 2 1
yaegi-0.10.0/_test/assign7.go 0000664 0000000 0000000 00000000352 14120400617 0015701 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := 3
t := map[string]int{"a": 1, "b": 2}
s := []int{4, 5}
fmt.Println(a, t["b"], s)
a, t["b"], s[1] = t["b"], s[1], a
fmt.Println(a, t["b"], s)
}
// Output:
// 3 2 [4 5]
// 2 5 [4 3]
yaegi-0.10.0/_test/assign8.go 0000664 0000000 0000000 00000000102 14120400617 0015673 0 ustar 00root root 0000000 0000000 package main
func main() {
_ = 1
println(1)
}
// Output:
// 1
yaegi-0.10.0/_test/assign9.go 0000664 0000000 0000000 00000000213 14120400617 0015677 0 ustar 00root root 0000000 0000000 package main
type foo func(b int)
func boo(b int) { println("boo", b) }
func main() {
var f foo
f = boo
f(4)
}
// Output:
// boo 4
yaegi-0.10.0/_test/b1/ 0000775 0000000 0000000 00000000000 14120400617 0014301 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/b1/foo/ 0000775 0000000 0000000 00000000000 14120400617 0015064 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/b1/foo/foo.go 0000664 0000000 0000000 00000000165 14120400617 0016200 0 ustar 00root root 0000000 0000000 package foo
import bar "github.com/traefik/yaegi/_test/b2/foo"
var Desc = "in b1/foo"
var Desc2 = Desc + bar.Desc
yaegi-0.10.0/_test/b2/ 0000775 0000000 0000000 00000000000 14120400617 0014302 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/b2/foo/ 0000775 0000000 0000000 00000000000 14120400617 0015065 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/b2/foo/foo.go 0000664 0000000 0000000 00000000044 14120400617 0016175 0 ustar 00root root 0000000 0000000 package foo
var Desc = "in b2/foo"
yaegi-0.10.0/_test/bad0.go 0000664 0000000 0000000 00000000106 14120400617 0015131 0 ustar 00root root 0000000 0000000 println("Hello")
// Error:
// 1:1: expected 'package', found println
yaegi-0.10.0/_test/baz-bat/ 0000775 0000000 0000000 00000000000 14120400617 0015317 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/baz-bat/baz-bat.go 0000664 0000000 0000000 00000000042 14120400617 0017162 0 ustar 00root root 0000000 0000000 package baz
var Name = "baz-bat"
yaegi-0.10.0/_test/bin.go 0000664 0000000 0000000 00000000137 14120400617 0015077 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
f := fmt.Println
f("Hello")
}
// Output:
// Hello
yaegi-0.10.0/_test/bin0.go 0000664 0000000 0000000 00000000177 14120400617 0015163 0 ustar 00root root 0000000 0000000 package main
import "strings"
func main() {
a := strings.SplitN("truc machin", " ", 2)
println(a[0])
}
// Output:
// truc
yaegi-0.10.0/_test/bin1.go 0000664 0000000 0000000 00000000346 14120400617 0015162 0 ustar 00root root 0000000 0000000 package main
import (
"crypto/sha1"
"fmt"
)
func main() {
d := sha1.New()
d.Write([]byte("password"))
a := d.Sum(nil)
fmt.Println(a)
}
// Output:
// [91 170 97 228 201 185 63 63 6 130 37 11 108 248 51 27 126 230 143 216]
yaegi-0.10.0/_test/bin2.go 0000664 0000000 0000000 00000000145 14120400617 0015160 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(math.Abs(-5))
}
// Output:
// 5
yaegi-0.10.0/_test/bin3.go 0000664 0000000 0000000 00000000213 14120400617 0015155 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
str := "part1"
str += fmt.Sprintf("%s", "part2")
fmt.Println(str)
}
// Output:
// part1part2
yaegi-0.10.0/_test/bin4.go 0000664 0000000 0000000 00000000471 14120400617 0015164 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"strings"
)
func Bar(s string) bool {
a := strings.HasPrefix("fas", "f")
b := strings.HasPrefix("aaaaa", "a")
a_and_b := strings.HasPrefix("fas", "f") && strings.HasPrefix("aaaaa", "a")
fmt.Println(a, b, a && b, a_and_b)
return a && b
}
func main() {
println(Bar("kung"))
}
yaegi-0.10.0/_test/bin5.go 0000664 0000000 0000000 00000000300 14120400617 0015154 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net"
)
func main() {
addr := net.TCPAddr{IP: net.IPv4(1, 1, 1, 1), Port: 80}
var s fmt.Stringer = &addr
fmt.Println(s.String())
}
// Output:
// 1.1.1.1:80
yaegi-0.10.0/_test/binstruct_ptr_map0.go 0000664 0000000 0000000 00000000306 14120400617 0020144 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"image"
)
func main() {
v := map[string]*image.Point{
"foo": {X: 3, Y: 2},
"bar": {X: 4, Y: 5},
}
fmt.Println(v["foo"], v["bar"])
}
// Output:
// (3,2) (4,5)
yaegi-0.10.0/_test/binstruct_ptr_slice0.go 0000664 0000000 0000000 00000000240 14120400617 0020463 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"image"
)
func main() {
v := []*image.Point{
{X: 3, Y: 2},
{X: 4, Y: 5},
}
fmt.Println(v)
}
// Output:
// [(3,2) (4,5)]
yaegi-0.10.0/_test/binstruct_slice0.go 0000664 0000000 0000000 00000000211 14120400617 0017574 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"image"
)
func main() {
v := []image.Point{
{X: 3, Y: 2},
}
fmt.Println(v)
}
// Output:
// [(3,2)]
yaegi-0.10.0/_test/bltn.go 0000664 0000000 0000000 00000000105 14120400617 0015261 0 ustar 00root root 0000000 0000000 package main
func main() {
println("Hello")
}
// Output:
// Hello
yaegi-0.10.0/_test/bltn0.go 0000664 0000000 0000000 00000000167 14120400617 0015351 0 ustar 00root root 0000000 0000000 package main
func main() {
f := println
f("Hello")
}
// Error:
// 4:7: use of builtin println not in function call
yaegi-0.10.0/_test/bool.go 0000664 0000000 0000000 00000000140 14120400617 0015254 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
fmt.Println(false, true)
}
// Output:
// false true
yaegi-0.10.0/_test/bool0.go 0000664 0000000 0000000 00000000123 14120400617 0015335 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
fmt.Println(true)
}
// Output:
// true
yaegi-0.10.0/_test/bool1.go 0000664 0000000 0000000 00000000216 14120400617 0015341 0 ustar 00root root 0000000 0000000 package main
type T struct {
v bool
}
func main() {
a := T{}
if a.v {
println("ok")
} else {
println("nok")
}
}
// Output:
// nok
yaegi-0.10.0/_test/bool2.go 0000664 0000000 0000000 00000000217 14120400617 0015343 0 ustar 00root root 0000000 0000000 package main
type T struct {
v bool
}
func main() {
a := &T{}
if a.v {
println("ok")
} else {
println("nok")
}
}
// Output:
// nok
yaegi-0.10.0/_test/bool3.go 0000664 0000000 0000000 00000000207 14120400617 0015343 0 ustar 00root root 0000000 0000000 package main
func main() {
m := map[int]bool{0: false, 1: true}
if m[0] {
println(0)
} else {
println(1)
}
}
// Output:
// 1
yaegi-0.10.0/_test/bool4.go 0000664 0000000 0000000 00000000173 14120400617 0015346 0 ustar 00root root 0000000 0000000 package main
func main() {
m := []bool{false, true}
if m[0] {
println(0)
} else {
println(1)
}
}
// Output:
// 1
yaegi-0.10.0/_test/bool5.go 0000664 0000000 0000000 00000000165 14120400617 0015350 0 ustar 00root root 0000000 0000000 package main
func main() {
var b bool
m := &b
if *m {
println(0)
} else {
println(1)
}
}
// Output:
// 1
yaegi-0.10.0/_test/c1/ 0000775 0000000 0000000 00000000000 14120400617 0014302 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/c1/c1.go 0000664 0000000 0000000 00000000115 14120400617 0015131 0 ustar 00root root 0000000 0000000 package c1
import "github.com/traefik/yaegi/_test/c2"
var C1 = c2.C2 + "x"
yaegi-0.10.0/_test/c2/ 0000775 0000000 0000000 00000000000 14120400617 0014303 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/c2/c2.go 0000664 0000000 0000000 00000000115 14120400617 0015133 0 ustar 00root root 0000000 0000000 package c2
import "github.com/traefik/yaegi/_test/c1"
var C2 = c1.C1 + "Y"
yaegi-0.10.0/_test/cap0.go 0000664 0000000 0000000 00000000302 14120400617 0015144 0 ustar 00root root 0000000 0000000 package main
func f(a []int) interface{} {
return cap(a)
}
func g(a []int) int {
return cap(a)
}
func main() {
a := []int{1, 2}
println(g(a))
println(f(a).(int))
}
// Output:
// 2
// 2
yaegi-0.10.0/_test/chan0.go 0000664 0000000 0000000 00000000276 14120400617 0015324 0 ustar 00root root 0000000 0000000 package main
type Channel chan string
func send(c Channel) { c <- "ping" }
func main() {
channel := make(Channel)
go send(channel)
msg := <-channel
println(msg)
}
// Output:
// ping
yaegi-0.10.0/_test/chan1.go 0000664 0000000 0000000 00000000256 14120400617 0015323 0 ustar 00root root 0000000 0000000 package main
func send(c chan<- string) { c <- "ping" }
func main() {
channel := make(chan string)
go send(channel)
msg := <-channel
println(msg)
}
// Output:
// ping
yaegi-0.10.0/_test/chan10.go 0000664 0000000 0000000 00000000233 14120400617 0015376 0 ustar 00root root 0000000 0000000 package main
import "time"
func main() {
var tick <-chan time.Time = time.Tick(time.Millisecond)
_ = tick
println("success")
}
// Output:
// success
yaegi-0.10.0/_test/chan2.go 0000664 0000000 0000000 00000000252 14120400617 0015320 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
messages := make(chan string)
go func() { messages <- "ping" }()
msg := <-messages
fmt.Println(msg)
}
// Output:
// ping
yaegi-0.10.0/_test/chan3.go 0000664 0000000 0000000 00000000250 14120400617 0015317 0 ustar 00root root 0000000 0000000 package main
func send(c chan<- int32) { c <- 123 }
func main() {
channel := make(chan int32)
go send(channel)
msg := <-channel
println(msg)
}
// Output:
// 123
yaegi-0.10.0/_test/chan4.go 0000664 0000000 0000000 00000000306 14120400617 0015322 0 ustar 00root root 0000000 0000000 package main
func send(c chan<- bool) { c <- false }
func main() {
channel := make(chan bool)
go send(channel)
if <-channel {
println("ok")
} else {
println("nok")
}
}
// Output:
// nok
yaegi-0.10.0/_test/chan5.go 0000664 0000000 0000000 00000000755 14120400617 0015333 0 ustar 00root root 0000000 0000000 package main
import "time"
func main() {
// For our example we'll select across two channels.
c1 := make(chan string)
c2 := make(chan string)
// Each channel will receive a value after some amount
// of time, to simulate e.g. blocking RPC operations
// executing in concurrent goroutines.
go func() {
//time.Sleep(1 * time.Second)
time.Sleep(1e9)
c1 <- "one"
}()
go func() {
time.Sleep(2e9)
c2 <- "two"
}()
msg1 := <-c1
println(msg1)
msg2 := <-c2
println(msg2)
}
yaegi-0.10.0/_test/chan6.go 0000664 0000000 0000000 00000000235 14120400617 0015325 0 ustar 00root root 0000000 0000000 package main
func send(c chan<- int32) { c <- 123 }
func main() {
channel := make(chan int32)
go send(channel)
msg, ok := <-channel
println(msg, ok)
}
yaegi-0.10.0/_test/chan7.go 0000664 0000000 0000000 00000000305 14120400617 0015324 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
queue := make(chan string, 2)
queue <- "one"
queue <- "two"
close(queue)
for elem := range queue {
fmt.Println(elem)
}
}
// Output:
// one
// two
yaegi-0.10.0/_test/chan8.go 0000664 0000000 0000000 00000000220 14120400617 0015321 0 ustar 00root root 0000000 0000000 package main
func main() {
messages := make(chan bool)
go func() { messages <- true }()
println(<-messages && true)
}
// Output:
// true
yaegi-0.10.0/_test/chan9.go 0000664 0000000 0000000 00000000352 14120400617 0015330 0 ustar 00root root 0000000 0000000 package main
type Channel chan string
type T struct {
Channel
}
func send(c Channel) { c <- "ping" }
func main() {
t := &T{}
t.Channel = make(Channel)
go send(t.Channel)
msg := <-t.Channel
println(msg)
}
// Output:
// ping
yaegi-0.10.0/_test/cli1.go 0000664 0000000 0000000 00000001516 14120400617 0015161 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io/ioutil"
"log"
"net"
"net/http"
)
func client(uri string) {
resp, err := http.Get(uri)
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}
func server(ln net.Listener, ready chan bool) {
http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
var r1 *http.Request = r
fmt.Fprintln(w, "Welcome to my website!", r1.RequestURI)
})
go http.Serve(ln, nil)
ready <- true
}
func main() {
ln, err := net.Listen("tcp", "localhost:0")
if err != nil {
log.Fatal(err)
}
defer ln.Close()
ready := make(chan bool)
go server(ln, ready)
<-ready
client(fmt.Sprintf("http://%s/hello", ln.Addr().String()))
http.DefaultServeMux = &http.ServeMux{}
}
// Output:
// Welcome to my website! /hello
yaegi-0.10.0/_test/cli2.go 0000664 0000000 0000000 00000001672 14120400617 0015165 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io/ioutil"
"log"
"net"
"net/http"
)
type T struct {
ln net.Listener
}
func (t *T) Close() {
t.ln.Close()
}
func client(uri string) {
resp, err := http.Get(uri)
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}
func server(ln net.Listener, ready chan bool) {
http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
var r1 *http.Request = r
fmt.Fprintln(w, "Welcome to my website!", r1.RequestURI)
})
go http.Serve(ln, nil)
ready <- true
}
func main() {
ln, err := net.Listen("tcp", "localhost:0")
t := &T{ln}
if err != nil {
log.Fatal(err)
}
defer t.Close()
// defer ln.Close()
ready := make(chan bool)
go server(ln, ready)
<-ready
client(fmt.Sprintf("http://%s/hello", ln.Addr().String()))
http.DefaultServeMux = &http.ServeMux{}
}
// Output:
// Welcome to my website! /hello
yaegi-0.10.0/_test/cli3.go 0000664 0000000 0000000 00000001056 14120400617 0015162 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
)
func client(uri string) {
resp, err := http.Get(uri)
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Welcome to my website!")
})
server := httptest.NewServer(mux)
defer server.Close()
client(server.URL)
}
// Output:
// Welcome to my website!
yaegi-0.10.0/_test/cli4.go 0000664 0000000 0000000 00000001410 14120400617 0015155 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
)
type mw1 struct {
next http.Handler
}
func (m *mw1) ServeHTTP(rw http.ResponseWriter, rq *http.Request) {
m.next.ServeHTTP(rw, rq)
}
type mw0 struct{}
func (m *mw0) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Welcome to my website!")
}
func main() {
m0 := &mw0{}
m1 := &mw1{m0}
mux := http.NewServeMux()
mux.HandleFunc("/", m1.ServeHTTP)
server := httptest.NewServer(mux)
defer server.Close()
client(server.URL)
}
func client(uri string) {
resp, err := http.Get(uri)
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}
// Output:
// Welcome to my website!
yaegi-0.10.0/_test/cli5.go 0000664 0000000 0000000 00000001416 14120400617 0015164 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
)
type mw1 struct {
next http.Handler
}
func (m *mw1) ServeHTTP(rw http.ResponseWriter, rq *http.Request) {
m.next.ServeHTTP(rw, rq)
}
type mw0 struct{}
func (m *mw0) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Welcome to my website!")
}
func main() {
m0 := &mw0{}
m1 := &mw1{next: m0}
mux := http.NewServeMux()
mux.HandleFunc("/", m1.ServeHTTP)
server := httptest.NewServer(mux)
defer server.Close()
client(server.URL)
}
func client(uri string) {
resp, err := http.Get(uri)
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}
// Output:
// Welcome to my website!
yaegi-0.10.0/_test/cli6.go 0000664 0000000 0000000 00000001353 14120400617 0015165 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
)
type T struct {
http.ResponseWriter
}
type mw1 struct {
next http.Handler
}
func (m *mw1) ServeHTTP(rw http.ResponseWriter, rq *http.Request) {
t := &T{
ResponseWriter: rw,
}
x := t.Header()
fmt.Fprint(rw, "Welcome to my website!", x)
}
func main() {
m1 := &mw1{}
mux := http.NewServeMux()
mux.HandleFunc("/", m1.ServeHTTP)
server := httptest.NewServer(mux)
defer server.Close()
client(server.URL)
}
func client(uri string) {
resp, err := http.Get(uri)
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}
// Output:
// Welcome to my website!map[]
yaegi-0.10.0/_test/closure0.go 0000664 0000000 0000000 00000000302 14120400617 0016055 0 ustar 00root root 0000000 0000000 package main
type adder func(int, int) int
func genAdd(k int) adder {
return func(i, j int) int {
return i + j + k
}
}
func main() {
f := genAdd(5)
println(f(3, 4))
}
// Output:
// 12
yaegi-0.10.0/_test/closure1.go 0000664 0000000 0000000 00000000352 14120400617 0016063 0 ustar 00root root 0000000 0000000 package main
type adder func(int, int) int
func genAdd(k int) adder {
return func(i, j int) int {
return i + j + k
}
}
func main() {
f := genAdd(5)
g := genAdd(8)
println(f(3, 4))
println(g(3, 4))
}
// Output:
// 12
// 15
yaegi-0.10.0/_test/closure10.go 0000664 0000000 0000000 00000000332 14120400617 0016141 0 ustar 00root root 0000000 0000000 package main
func main() {
foos := []func(){}
for i := 0; i < 3; i++ {
a, b := i, i
foos = append(foos, func() { println(i, a, b) })
}
foos[0]()
foos[1]()
foos[2]()
}
// Output:
// 3 0 0
// 3 1 1
// 3 2 2
yaegi-0.10.0/_test/closure11.go 0000664 0000000 0000000 00000000354 14120400617 0016146 0 ustar 00root root 0000000 0000000 package main
type T struct {
F func()
}
func main() {
foos := []T{}
for i := 0; i < 3; i++ {
a := i
foos = append(foos, T{func() { println(i, a) }})
}
foos[0].F()
foos[1].F()
foos[2].F()
}
// Output:
// 3 0
// 3 1
// 3 2
yaegi-0.10.0/_test/closure12.go 0000664 0000000 0000000 00000000447 14120400617 0016152 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T struct {
F func()
}
func main() {
foos := []T{}
for i := 0; i < 3; i++ {
a := i
n := fmt.Sprintf("i=%d", i)
foos = append(foos, T{func() { println(i, a, n) }})
}
foos[0].F()
foos[1].F()
foos[2].F()
}
// Output:
// 3 0 i=0
// 3 1 i=1
// 3 2 i=2
yaegi-0.10.0/_test/closure2.go 0000664 0000000 0000000 00000000503 14120400617 0016062 0 ustar 00root root 0000000 0000000 package main
func adder() func(int) int {
sum := 0
return func(x int) int {
sum = sum + x
return sum
}
}
func main() {
pos, neg := adder(), adder()
for i := 0; i < 10; i++ {
println(pos(i), neg(-2*i))
}
}
// Output:
// 0 0
// 1 -2
// 3 -6
// 6 -12
// 10 -20
// 15 -30
// 21 -42
// 28 -56
// 36 -72
// 45 -90
yaegi-0.10.0/_test/closure3.go 0000664 0000000 0000000 00000000372 14120400617 0016067 0 ustar 00root root 0000000 0000000 package main
type T1 struct {
Name string
}
func (t *T1) genAdd(k int) func(int) int {
return func(i int) int {
println(t.Name)
return i + k
}
}
var t = &T1{"test"}
func main() {
f := t.genAdd(4)
println(f(5))
}
// Output:
// test
// 9
yaegi-0.10.0/_test/closure4.go 0000664 0000000 0000000 00000000371 14120400617 0016067 0 ustar 00root root 0000000 0000000 package main
type T1 struct {
Name string
}
func (t *T1) genAdd(k int) func(int) int {
return func(i int) int {
println(t.Name)
return i + k
}
}
var t = T1{"test"}
func main() {
f := t.genAdd(4)
println(f(5))
}
// Output:
// test
// 9
yaegi-0.10.0/_test/closure5.go 0000664 0000000 0000000 00000000370 14120400617 0016067 0 ustar 00root root 0000000 0000000 package main
type T1 struct {
Name string
}
func (t T1) genAdd(k int) func(int) int {
return func(i int) int {
println(t.Name)
return i + k
}
}
var t = T1{"test"}
func main() {
f := t.genAdd(4)
println(f(5))
}
// Output:
// test
// 9
yaegi-0.10.0/_test/closure6.go 0000664 0000000 0000000 00000000372 14120400617 0016072 0 ustar 00root root 0000000 0000000 package main
type T1 struct {
Name string
}
func (t *T1) genAdd(k int) func(int) int {
return func(i int) int {
println(t.Name)
return i + k
}
}
var t = &T1{"test"}
func main() {
f := t.genAdd(4)
println(f(5))
}
// Output:
// test
// 9
yaegi-0.10.0/_test/closure7.go 0000664 0000000 0000000 00000000411 14120400617 0016065 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
type Config struct {
A string
}
var conf *Config = &Config{}
func SetConfig() func(*Config) {
return func(cf *Config) {
conf = cf
}
}
func main() {
conf := &Config{
A: "foo",
}
fmt.Println(conf.A)
}
// Output:
// foo
yaegi-0.10.0/_test/closure8.go 0000664 0000000 0000000 00000000150 14120400617 0016066 0 ustar 00root root 0000000 0000000 package main
var f = func(a int) int { return 2 + a }
func main() {
println(f(3))
}
// Output:
// 5
yaegi-0.10.0/_test/closure9.go 0000664 0000000 0000000 00000000313 14120400617 0016070 0 ustar 00root root 0000000 0000000 package main
func main() {
foos := []func(){}
for i := 0; i < 3; i++ {
a := i
foos = append(foos, func() { println(i, a) })
}
foos[0]()
foos[1]()
foos[2]()
}
// Output:
// 3 0
// 3 1
// 3 2
yaegi-0.10.0/_test/comp0.go 0000664 0000000 0000000 00000000104 14120400617 0015337 0 ustar 00root root 0000000 0000000 package main
func main() {
println(2 < 2.4)
}
// Output:
// true
yaegi-0.10.0/_test/comp1.go 0000664 0000000 0000000 00000000140 14120400617 0015340 0 ustar 00root root 0000000 0000000 package main
func main() {
var a interface{} = 1 < 2
println(a.(bool))
}
// Output:
// true
yaegi-0.10.0/_test/comp2.go 0000664 0000000 0000000 00000000202 14120400617 0015340 0 ustar 00root root 0000000 0000000 package main
type delta int32
func main() {
a := delta(-1)
println(a != -1)
println(a == -1)
}
// Output:
// false
// true
yaegi-0.10.0/_test/complex0.go 0000664 0000000 0000000 00000000174 14120400617 0016057 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := complex(3, 2)
fmt.Println(a, real(a), imag(a))
}
// Output:
// (3+2i) 3 2
yaegi-0.10.0/_test/complex1.go 0000664 0000000 0000000 00000000203 14120400617 0016051 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var c complex128
c = 1
fmt.Printf("%T %v\n", c, c)
}
// Output:
// complex128 (1+0i)
yaegi-0.10.0/_test/complex2.go 0000664 0000000 0000000 00000000206 14120400617 0016055 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
c := complex(1, 0)
c += 1
fmt.Printf("%T %v\n", c, c)
}
// Output:
// complex128 (2+0i)
yaegi-0.10.0/_test/complex3.go 0000664 0000000 0000000 00000000175 14120400617 0016063 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var s int = 1 + complex(1, 0)
fmt.Printf("%T %v\n", s, s)
}
// Output:
// int 2
yaegi-0.10.0/_test/complex4.go 0000664 0000000 0000000 00000000250 14120400617 0016056 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f(a, b float64) interface{} { return complex(a, b) }
func main() {
a := f(3, 2)
fmt.Println(a.(complex128))
}
// Output:
// (3+2i)
yaegi-0.10.0/_test/composite0.go 0000664 0000000 0000000 00000000176 14120400617 0016414 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var a = &[]*T{}
type T struct{ name string }
func main() {
fmt.Println(a)
}
// Output:
// &[]
yaegi-0.10.0/_test/composite1.go 0000664 0000000 0000000 00000000206 14120400617 0016407 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var a = &[]*T{{}}
type T struct{ name string }
func main() {
fmt.Println((*a)[0])
}
// Output:
// &{}
yaegi-0.10.0/_test/composite10.go 0000664 0000000 0000000 00000000224 14120400617 0016467 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := []map[int]int{make(map[int]int)}
for _, b := range a {
fmt.Println(b)
}
}
// Output:
// map[]
yaegi-0.10.0/_test/composite11.go 0000664 0000000 0000000 00000000212 14120400617 0016465 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"image/color"
)
func main() {
c := color.NRGBA64{1, 1, 1, 1}
fmt.Println(c)
}
// Output:
// {1 1 1 1}
yaegi-0.10.0/_test/composite12.go 0000664 0000000 0000000 00000000217 14120400617 0016473 0 ustar 00root root 0000000 0000000 package main
type A struct {
C D
}
type D struct {
E string
}
func main() {
a := A{}
a.C = D{"bb"}
println(a.C.E)
}
// Output:
// bb
yaegi-0.10.0/_test/composite13.go 0000664 0000000 0000000 00000000222 14120400617 0016470 0 ustar 00root root 0000000 0000000 package main
type A struct {
C D
}
type D struct {
E string
}
func main() {
a := A{}
a.C = D{E: "bb"}
println(a.C.E)
}
// Output:
// bb
yaegi-0.10.0/_test/composite14.go 0000664 0000000 0000000 00000000172 14120400617 0016475 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T struct {
b []byte
}
func main() {
t := T{nil}
fmt.Println(t)
}
// Output:
// {[]}
yaegi-0.10.0/_test/composite15.go 0000664 0000000 0000000 00000001042 14120400617 0016473 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
func interfaceAsInts() {
var a interface{}
b := 2
c := 3
a = []int{b, c}
d, ok := a.([]int)
if !ok {
println("nope")
return
}
for _, v := range d {
fmt.Println(v)
}
}
func interfaceAsInterfaces() {
var a, b, c interface{}
b = 2
c = 3
a = []interface{}{b, c}
d, ok := a.([]interface{})
if !ok {
println("nope")
return
}
fmt.Println(d)
for _, v := range d {
fmt.Println(v)
}
}
func main() {
interfaceAsInts()
interfaceAsInterfaces()
}
// Output:
// 2
// 3
// [2 3]
// 2
// 3
yaegi-0.10.0/_test/composite16.go 0000664 0000000 0000000 00000000237 14120400617 0016501 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/url"
)
func main() {
body := url.Values{
"Action": {"none"},
}
fmt.Println(body)
}
// Output:
// map[Action:[none]]
yaegi-0.10.0/_test/composite17.go 0000664 0000000 0000000 00000000573 14120400617 0016505 0 ustar 00root root 0000000 0000000 package main
import (
"html/template"
)
var str = `{{ stringOr .Data "test" }}`
func main() {
_, err := template.New("test").
Funcs(template.FuncMap{
"stringOr": stringOr,
}).
Parse(str)
if err != nil {
println(err.Error())
return
}
println("success")
}
func stringOr(v, def string) string {
if v == "" {
return def
}
return v
}
// Output:
// success
yaegi-0.10.0/_test/composite18.go 0000664 0000000 0000000 00000000564 14120400617 0016506 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type fn func(string, string) bool
var funcs = []fn{
cmpLessFn,
cmpGreaterFn,
nil,
}
func cmpLessFn(a string, b string) bool {
return a < b
}
func cmpGreaterFn(a string, b string) bool {
return a > b
}
func main() {
for _, f := range funcs {
if f == nil {
continue
}
fmt.Println(f("a", "b"))
}
}
// Output:
// true
// false
yaegi-0.10.0/_test/composite19.go 0000664 0000000 0000000 00000000715 14120400617 0016505 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type fn func(string, string) bool
var funcs = map[string]fn{
"less": cmpLessFn,
"greater": cmpGreaterFn,
"none": nil,
}
func cmpLessFn(a string, b string) bool {
return a < b
}
func cmpGreaterFn(a string, b string) bool {
return a > b
}
func main() {
for _, n := range []string{"less", "greater", "none"} {
f := funcs[n]
if f == nil {
continue
}
fmt.Println(f("a", "b"))
}
}
// Output:
// true
// false
yaegi-0.10.0/_test/composite2.go 0000664 0000000 0000000 00000000222 14120400617 0016406 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var a = &[]*T{{"hello"}}
type T struct{ name string }
func main() {
fmt.Println((*a)[0])
}
// Output:
// &{hello}
yaegi-0.10.0/_test/composite3.go 0000664 0000000 0000000 00000000206 14120400617 0016411 0 ustar 00root root 0000000 0000000 package main
func main() {
var err error
var ok bool
_, ok = err.(interface{ IsSet() bool })
println(ok)
}
// Output:
// false
yaegi-0.10.0/_test/composite4.go 0000664 0000000 0000000 00000000172 14120400617 0016414 0 ustar 00root root 0000000 0000000 package main
func main() {
var err error
_, ok := err.(interface{ IsSet() bool })
println(ok)
}
// Output:
// false
yaegi-0.10.0/_test/composite5.go 0000664 0000000 0000000 00000000205 14120400617 0016412 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T struct {
m uint16
}
var t = T{1<<2 | 1<<3}
func main() {
fmt.Println(t)
}
// Output:
// {12}
yaegi-0.10.0/_test/composite6.go 0000664 0000000 0000000 00000000257 14120400617 0016422 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"github.com/traefik/yaegi/_test/ct1"
)
type T struct {
m uint16
}
var t = T{1 << ct1.R}
func main() {
fmt.Println(t)
}
// Output:
// {2}
yaegi-0.10.0/_test/composite7.go 0000664 0000000 0000000 00000000265 14120400617 0016422 0 ustar 00root root 0000000 0000000 package main
type T struct {
name string
}
var tab = []*T{{
name: "foo",
}, {
name: "bar",
}}
func main() {
println(len(tab))
println(tab[0].name)
}
// Output:
// 2
// foo
yaegi-0.10.0/_test/composite8.go 0000664 0000000 0000000 00000000273 14120400617 0016422 0 ustar 00root root 0000000 0000000 package main
type T struct{ I int }
func main() {
t := []*T{}
s := []int{1, 2}
for _, e := range s {
x := &T{e}
t = append(t, x)
}
println(t[0].I, t[1].I)
}
// Output:
// 1 2
yaegi-0.10.0/_test/composite8bis.go 0000664 0000000 0000000 00000000276 14120400617 0017123 0 ustar 00root root 0000000 0000000 package main
type T struct{ I int }
func main() {
t := []*T{}
s := []int{1, 2}
for _, e := range s {
x := &T{I: e}
t = append(t, x)
}
println(t[0].I, t[1].I)
}
// Output:
// 1 2
yaegi-0.10.0/_test/composite9.go 0000664 0000000 0000000 00000000207 14120400617 0016420 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [][]int{make([]int,0)}
for _, b := range a {
fmt.Println(b)
}
}
// Output:
// []
yaegi-0.10.0/_test/const0.go 0000664 0000000 0000000 00000000130 14120400617 0015526 0 ustar 00root root 0000000 0000000 package main
const (
a = iota
b
)
func main() {
println(a, b)
}
// Output:
// 0 1
yaegi-0.10.0/_test/const1.go 0000664 0000000 0000000 00000000203 14120400617 0015530 0 ustar 00root root 0000000 0000000 package main
type T struct {
a int
b string
}
var t = T{1, "hello"}
func main() {
println(t.a, t.b)
}
// Output:
// 1 hello
yaegi-0.10.0/_test/const10.go 0000664 0000000 0000000 00000000175 14120400617 0015620 0 ustar 00root root 0000000 0000000 package main
const (
a = 2
b = c + d
c = a + d
d = e + f
e = 3
f = 4
)
func main() {
println(b)
}
// Output:
// 16
yaegi-0.10.0/_test/const11.go 0000664 0000000 0000000 00000000175 14120400617 0015621 0 ustar 00root root 0000000 0000000 package main
func main() {
const (
x = 2 * iota
dim
)
var t [dim * 2]int
println(t[0], len(t))
}
// Output:
// 0 4
yaegi-0.10.0/_test/const12.go 0000664 0000000 0000000 00000000270 14120400617 0015616 0 ustar 00root root 0000000 0000000 package main
type Kind int
const (
None Kind = 0
Left Kind = 1 << iota
Right
Both Kind = Left | Right
)
func main() {
println(None, Left, Right, Both)
}
// Output:
// 0 2 4 6
yaegi-0.10.0/_test/const13.go 0000664 0000000 0000000 00000000321 14120400617 0015614 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
func main() {
const tooBig = 1267650600228229401496703205376
const huge = 1 << 100
const large = huge >> 38
fmt.Println(int64(large))
}
// Output:
// 4611686018427387904
yaegi-0.10.0/_test/const14.go 0000664 0000000 0000000 00000000215 14120400617 0015617 0 ustar 00root root 0000000 0000000 package main
import "compress/flate"
func f1(i int) { println("i:", i) }
func main() {
i := flate.BestSpeed
f1(i)
}
// Output:
// i: 1
yaegi-0.10.0/_test/const15.go 0000664 0000000 0000000 00000000167 14120400617 0015626 0 ustar 00root root 0000000 0000000 package main
type T1 t1
type t1 int8
const (
P2 T1 = 2
P3 T1 = 3
)
func main() {
println(P3)
}
// Output:
// 3
yaegi-0.10.0/_test/const16.go 0000664 0000000 0000000 00000000126 14120400617 0015622 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
func main() {
fmt.Println(7 / 3)
}
// Output:
// 2
yaegi-0.10.0/_test/const17.go 0000664 0000000 0000000 00000000171 14120400617 0015623 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var t [7/3]int
func main() {
t[0] = 3/2
t[1] = 5/2
fmt.Println(t)
}
// Output:
// [1 2]
yaegi-0.10.0/_test/const18.go 0000664 0000000 0000000 00000000154 14120400617 0015625 0 ustar 00root root 0000000 0000000 package main
import "time"
func main() {
a := int64(time.Second)
println(a)
}
// Output:
// 1000000000
yaegi-0.10.0/_test/const19.go 0000664 0000000 0000000 00000000260 14120400617 0015624 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func get10Hours() time.Duration {
return 10 * time.Hour
}
func main() {
fmt.Println(get10Hours().String())
}
// Output:
// 10h0m0s
yaegi-0.10.0/_test/const2.go 0000664 0000000 0000000 00000000122 14120400617 0015531 0 ustar 00root root 0000000 0000000 package main
func main() {
println(a)
}
const a = "hello"
// Output:
// hello
yaegi-0.10.0/_test/const20.go 0000664 0000000 0000000 00000000222 14120400617 0015612 0 ustar 00root root 0000000 0000000 package main
import "fmt"
const maxLen = int64(int64(^uint64(0) >> 1))
func main() {
fmt.Println(maxLen)
}
// Output:
// 9223372036854775807
yaegi-0.10.0/_test/const21.go 0000664 0000000 0000000 00000000144 14120400617 0015616 0 ustar 00root root 0000000 0000000 package main
const a = 64
var b uint = a * a / 2
func main() {
println(b)
}
// Output:
// 2048
yaegi-0.10.0/_test/const22.go 0000664 0000000 0000000 00000000225 14120400617 0015617 0 ustar 00root root 0000000 0000000 package main
const (
numDec uint8 = (1 << iota) / 2
numHex
numOct
numFloat
)
func main() {
println(13 & (numHex | numOct))
}
// Output:
// 1
yaegi-0.10.0/_test/const23.go 0000664 0000000 0000000 00000000171 14120400617 0015620 0 ustar 00root root 0000000 0000000 package main
const maxlen = len("hello")
var gfm = [maxlen]byte{}
func main() {
println(len(gfm))
}
// Output:
// 5
yaegi-0.10.0/_test/const24.go 0000664 0000000 0000000 00000000220 14120400617 0015614 0 ustar 00root root 0000000 0000000 package main
var aa = [...]int{1, 2, 3}
const maxlen = cap(aa)
var gfm = [maxlen]byte{}
func main() {
println(len(gfm))
}
// Output:
// 3
yaegi-0.10.0/_test/const25.go 0000664 0000000 0000000 00000000156 14120400617 0015625 0 ustar 00root root 0000000 0000000 package main
const (
FGBlack Attribute = iota + 30
)
type Attribute int
func main() {
println(FGBlack)
}
yaegi-0.10.0/_test/const26.go 0000664 0000000 0000000 00000000435 14120400617 0015626 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
func init() {
fmt.Println(constString)
fmt.Println(const2)
fmt.Println(varString)
}
const constString string = "hello"
const (
const1 = iota + 10
const2
const3
)
var varString string = "test"
func main() {}
// Output:
// hello
// 11
// test
yaegi-0.10.0/_test/const3.go 0000664 0000000 0000000 00000000141 14120400617 0015533 0 ustar 00root root 0000000 0000000 package main
const a, b, c int = 1, 2, 3
func main() { println(a, b, c) }
// Output:
// 1 2 3
yaegi-0.10.0/_test/const4.go 0000664 0000000 0000000 00000000141 14120400617 0015534 0 ustar 00root root 0000000 0000000 package main
const (
a = 2
b = 3
c
)
func main() {
println(a, b, c)
}
// Output:
// 2 3 3
yaegi-0.10.0/_test/const5.go 0000664 0000000 0000000 00000000241 14120400617 0015536 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
const (
a uint8 = 2 * iota
b
c
)
func main() {
fmt.Printf("%T\n", c)
fmt.Println(a, b, c)
}
// Output:
// uint8
// 0 2 4
yaegi-0.10.0/_test/const6.go 0000664 0000000 0000000 00000000414 14120400617 0015541 0 ustar 00root root 0000000 0000000 package main
const (
maxNonStarters = 30
maxBufferSize = maxNonStarters + 2
)
type reorderBuffer struct {
rune [maxBufferSize]Properties
}
type Properties struct {
pos uint8
size uint8
}
func main() {
println(len(reorderBuffer{}.rune))
}
// Output:
// 32
yaegi-0.10.0/_test/const7.go 0000664 0000000 0000000 00000000200 14120400617 0015533 0 ustar 00root root 0000000 0000000 package main
import "fmt"
const (
a = iota
b
c
d
)
type T [c]int
func main() {
fmt.Println(T{})
}
// Output:
// [0 0]
yaegi-0.10.0/_test/const8.go 0000664 0000000 0000000 00000000165 14120400617 0015546 0 ustar 00root root 0000000 0000000 package main
const (
a = 2
b = c + d
c = 4
d = 5
)
func main() {
println(a, b, c, d)
}
// Output:
// 2 9 4 5
yaegi-0.10.0/_test/const9.go 0000664 0000000 0000000 00000000233 14120400617 0015543 0 ustar 00root root 0000000 0000000 package main
const (
a = 2
b = c + d
c = a + d
d = e + f
e = b + 2
f = 4
)
func main() {
println(b)
}
// Error:
// 5:2: constant definition loop
yaegi-0.10.0/_test/cont.go 0000664 0000000 0000000 00000000213 14120400617 0015265 0 ustar 00root root 0000000 0000000 package main
func main() {
for i := 0; i < 10; i++ {
if i < 5 {
continue
}
println(i)
}
}
// Output:
// 5
// 6
// 7
// 8
// 9
yaegi-0.10.0/_test/cont0.go 0000664 0000000 0000000 00000000254 14120400617 0015352 0 ustar 00root root 0000000 0000000 package main
func main() {
i := 0
for {
if i > 10 {
break
}
i++
if i < 5 {
continue
}
println(i)
}
}
// Output:
// 5
// 6
// 7
// 8
// 9
// 10
// 11
yaegi-0.10.0/_test/cont1.go 0000664 0000000 0000000 00000000255 14120400617 0015354 0 ustar 00root root 0000000 0000000 package main
func main() {
i := 0
for {
if i > 10 {
break
}
if i < 5 {
i++
continue
}
println(i)
i++
}
}
// Output:
// 5
// 6
// 7
// 8
// 9
// 10
yaegi-0.10.0/_test/context.go 0000664 0000000 0000000 00000000445 14120400617 0016015 0 ustar 00root root 0000000 0000000 package main
import "context"
func get(ctx context.Context, k string) string {
var r string
if v := ctx.Value(k); v != nil {
r = v.(string)
}
return r
}
func main() {
ctx := context.WithValue(context.Background(), "hello", "world")
println(get(ctx, "hello"))
}
// Output:
// world
yaegi-0.10.0/_test/context2.go 0000664 0000000 0000000 00000000514 14120400617 0016074 0 ustar 00root root 0000000 0000000 package main
import "context"
func get(ctx context.Context, k string) string {
var r string
var ok bool
if v := ctx.Value(k); v != nil {
r, ok = v.(string)
println(ok)
}
return r
}
func main() {
ctx := context.WithValue(context.Background(), "hello", "world")
println(get(ctx, "hello"))
}
// Output:
// true
// world
yaegi-0.10.0/_test/convert0.go 0000664 0000000 0000000 00000000411 14120400617 0016062 0 ustar 00root root 0000000 0000000 package main
type T struct {
v int
}
type comparator func(T, T) bool
func sort(items []T, comp comparator) {
println("in sort")
}
func compT(t0, t1 T) bool { return t0.v < t1.v }
func main() {
a := []T{}
sort(a, comparator(compT))
}
// Output:
// in sort
yaegi-0.10.0/_test/convert1.go 0000664 0000000 0000000 00000000322 14120400617 0016064 0 ustar 00root root 0000000 0000000 package main
import "strconv"
type atoidef func(s string) (int, error)
func main() {
stdatoi := atoidef(strconv.Atoi)
n, err := stdatoi("7")
if err != nil {
panic(err)
}
println(n)
}
// Output:
// 7
yaegi-0.10.0/_test/convert2.go 0000664 0000000 0000000 00000000450 14120400617 0016067 0 ustar 00root root 0000000 0000000 package main
import "bufio"
func fakeSplitFunc(data []byte, atEOF bool) (advance int, token []byte, err error) {
return 7, nil, nil
}
func main() {
splitfunc := bufio.SplitFunc(fakeSplitFunc)
n, _, err := splitfunc(nil, true)
if err != nil {
panic(err)
}
println(n)
}
// Output:
// 7
yaegi-0.10.0/_test/copy0.go 0000664 0000000 0000000 00000000226 14120400617 0015360 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := []int{10, 20, 30}
b := [4]int{}
c := b[:]
copy(c, a)
fmt.Println(c)
}
// Output:
// [10 20 30 0]
yaegi-0.10.0/_test/copy1.go 0000664 0000000 0000000 00000000227 14120400617 0015362 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := []int{10, 20, 30}
b := &[4]int{}
c := b[:]
copy(c, a)
fmt.Println(c)
}
// Output:
// [10 20 30 0]
yaegi-0.10.0/_test/copy2.go 0000664 0000000 0000000 00000000311 14120400617 0015355 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f(a, b []int) interface{} { return copy(a, b) }
func main() {
a := []int{10, 20, 30}
b := [4]int{}
c := b[:]
r := f(c, a)
fmt.Println(r.(int))
}
// Output:
// 3
yaegi-0.10.0/_test/ct/ 0000775 0000000 0000000 00000000000 14120400617 0014405 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/ct/ct1.go 0000664 0000000 0000000 00000000066 14120400617 0015425 0 ustar 00root root 0000000 0000000 package ct
func init() { println("hello from ct1") }
yaegi-0.10.0/_test/ct/ct2.go 0000664 0000000 0000000 00000000110 14120400617 0015414 0 ustar 00root root 0000000 0000000 // +build !dummy
package ct
func init() { println("hello from ct2") }
yaegi-0.10.0/_test/ct/ct3.go 0000664 0000000 0000000 00000000107 14120400617 0015423 0 ustar 00root root 0000000 0000000 // +build dummy
package ct
func init() { println("hello from ct3") }
yaegi-0.10.0/_test/ct1/ 0000775 0000000 0000000 00000000000 14120400617 0014466 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/ct1/ct1.go 0000664 0000000 0000000 00000000077 14120400617 0015510 0 ustar 00root root 0000000 0000000 package ct1
type Class uint
const (
L Class = iota
R
AL
)
yaegi-0.10.0/_test/d1/ 0000775 0000000 0000000 00000000000 14120400617 0014303 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/d1/d1.go 0000664 0000000 0000000 00000000171 14120400617 0015135 0 ustar 00root root 0000000 0000000 package d1
type T struct {
Name string
}
func (t *T) F() { println(t.Name) }
func NewT(s string) *T { return &T{s} }
yaegi-0.10.0/_test/d2/ 0000775 0000000 0000000 00000000000 14120400617 0014304 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/d2/d2.go 0000664 0000000 0000000 00000000136 14120400617 0015140 0 ustar 00root root 0000000 0000000 package d2
import "github.com/traefik/yaegi/_test/d1"
var (
X = d1.NewT("test")
F = X.F
)
yaegi-0.10.0/_test/d3.go 0000664 0000000 0000000 00000000156 14120400617 0014636 0 ustar 00root root 0000000 0000000 package main
import "github.com/traefik/yaegi/_test/d2"
func main() {
f := d2.F
f()
}
// Output:
// test
yaegi-0.10.0/_test/defer0.go 0000664 0000000 0000000 00000000274 14120400617 0015476 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
println("hello")
defer fmt.Println("bye")
defer fmt.Println("au revoir")
println("world")
}
// Output:
// hello
// world
// au revoir
// bye
yaegi-0.10.0/_test/defer1.go 0000664 0000000 0000000 00000000237 14120400617 0015476 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
println("hello")
defer func() {
fmt.Println("bye")
}()
println("world")
}
// Output:
// hello
// world
// bye
yaegi-0.10.0/_test/defer2.go 0000664 0000000 0000000 00000000264 14120400617 0015477 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
println("hello")
i := 12
defer func() {
fmt.Println("i:", i)
}()
i = 20
println("world")
}
// Output:
// hello
// world
// i: 20
yaegi-0.10.0/_test/defer3.go 0000664 0000000 0000000 00000000306 14120400617 0015475 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"net/http/httptest"
)
func main() {
println("hello")
mux := http.NewServeMux()
server := httptest.NewServer(mux)
defer server.Close()
}
// Output:
// hello
yaegi-0.10.0/_test/defer4.go 0000664 0000000 0000000 00000000360 14120400617 0015476 0 ustar 00root root 0000000 0000000 package main
import "sync"
type T struct {
mu sync.RWMutex
name string
}
func (t *T) get() string {
t.mu.RLock()
defer t.mu.RUnlock()
return t.name
}
var d = T{name: "test"}
func main() {
println(d.get())
}
// Output:
// test
yaegi-0.10.0/_test/defer5.go 0000664 0000000 0000000 00000000542 14120400617 0015501 0 ustar 00root root 0000000 0000000 package main
func f1() {
defer println("f1-begin")
f2()
defer println("f1-end")
}
func f2() {
defer println("f2-begin")
f3()
defer println("f2-end")
}
func f3() {
defer println("f3-begin")
println("hello")
defer println("f3-end")
}
func main() {
f1()
}
// Output:
// hello
// f3-end
// f3-begin
// f2-end
// f2-begin
// f1-end
// f1-begin
yaegi-0.10.0/_test/defer6.go 0000664 0000000 0000000 00000000524 14120400617 0015502 0 ustar 00root root 0000000 0000000 package main
func f1() {
defer print("f1-begin ")
f2()
defer print("f1-end ")
}
func f2() {
defer print("f2-begin ")
f3()
defer print("f2-end ")
}
func f3() {
defer print("f3-begin ")
print("hello ")
defer print("f3-end ")
}
func main() {
f1()
println()
}
// Output:
// hello f3-end f3-begin f2-end f2-begin f1-end f1-begin
yaegi-0.10.0/_test/defer7.go 0000664 0000000 0000000 00000000321 14120400617 0015476 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f1(in, out []string) {
defer copy(out, in)
}
func main() {
in := []string{"foo", "bar"}
out := make([]string, 2)
f1(in, out)
fmt.Println(out)
}
// Output:
// [foo bar]
yaegi-0.10.0/_test/defer8.go 0000664 0000000 0000000 00000000430 14120400617 0015500 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f1(m map[string]string) {
defer delete(m, "foo")
defer delete(m, "test")
fmt.Println(m)
}
func main() {
m := map[string]string{
"foo": "bar",
"baz": "bat",
}
f1(m)
fmt.Println(m)
}
// Output:
// map[baz:bat foo:bar]
// map[baz:bat]
yaegi-0.10.0/_test/defer9.go 0000664 0000000 0000000 00000000311 14120400617 0015477 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f1(ch chan string) {
defer close(ch)
ch <- "foo"
}
func main() {
ch := make(chan string, 1)
f1(ch)
for s := range ch {
fmt.Println(s)
}
}
// Output:
// foo
yaegi-0.10.0/_test/delete0.go 0000664 0000000 0000000 00000000231 14120400617 0015644 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := map[string]int{"hello": 1, "world": 3}
delete(a, "hello")
fmt.Println(a)
}
// Output:
// map[world:3]
yaegi-0.10.0/_test/eval0.go 0000664 0000000 0000000 00000000654 14120400617 0015342 0 ustar 00root root 0000000 0000000 package main
import (
"log"
"os"
"github.com/traefik/yaegi/interp"
)
func main() {
log.SetFlags(log.Lshortfile)
i := interp.New(interp.Options{Stdout: os.Stdout})
if _, err := i.Eval(`func f() (int, int) { return 1, 2 }`); err != nil {
log.Fatal(err)
}
if _, err := i.Eval(`a, b := f()`); err != nil {
log.Fatal(err)
}
if _, err := i.Eval(`println(a, b)`); err != nil {
log.Fatal(err)
}
}
// Output:
// 1 2
yaegi-0.10.0/_test/export0.go 0000664 0000000 0000000 00000000111 14120400617 0015720 0 ustar 00root root 0000000 0000000 package main
func Test() {
println("Hello from test")
}
// Output:
//
yaegi-0.10.0/_test/export1.go 0000664 0000000 0000000 00000000202 14120400617 0015722 0 ustar 00root root 0000000 0000000 package sample
type Sample struct{ Name string }
func (s *Sample) Test() {
println("Hello from test", s.Name)
}
// Output:
//
yaegi-0.10.0/_test/factor.go 0000664 0000000 0000000 00000001075 14120400617 0015607 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/big"
)
func main() {
// 157 bit n = pq with p ~= 78 bits
n := big.NewInt(0)
n.SetString("273966616513101251352941655302036077733021013991", 10)
i := big.NewInt(0)
// Set i to be p - 10e6
i.SetString("496968652506233112158689", 10)
// Move temp big int out here so no possible GC thrashing
temp := big.NewInt(0)
// Avoid creating the new bigint each time
two := big.NewInt(2)
for {
// Check if the odd number is a divisor of n
temp.Mod(n, i)
if temp.Sign() == 0 {
fmt.Println(i)
break
}
i.Add(i, two)
}
}
yaegi-0.10.0/_test/fib.go 0000664 0000000 0000000 00000000300 14120400617 0015057 0 ustar 00root root 0000000 0000000 package main
// Compute fibonacci numbers, no memoization
func fib(n int) int {
if n < 2 {
return n
}
return fib(n-2) + fib(n-1)
}
func main() {
println(fib(35))
//println(fib(10))
}
yaegi-0.10.0/_test/fib0.go 0000664 0000000 0000000 00000000274 14120400617 0015151 0 ustar 00root root 0000000 0000000 package main
// Compute fibonacci numbers, no memoization
func fib(n int) int {
if n < 2 {
return n
}
return fib(n-2) + fib(n-1)
}
func main() {
println(fib(4))
}
// Output:
// 3
yaegi-0.10.0/_test/file_access.go 0000664 0000000 0000000 00000000777 14120400617 0016601 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io/ioutil"
"os"
)
func main() {
file, err := ioutil.TempFile("", "yeagibench")
if err != nil {
panic(err)
}
n, err := file.Write([]byte("hello world"))
if err != nil {
panic(err)
}
fmt.Println("n:", n)
err = file.Close()
if err != nil {
panic(err)
}
b, err := ioutil.ReadFile(file.Name())
if err != nil {
panic(err)
}
fmt.Println("b:", string(b))
err = os.Remove(file.Name())
if err != nil {
panic(err)
}
}
// Output:
// n: 11
// b: hello world
yaegi-0.10.0/_test/flag0.go 0000664 0000000 0000000 00000000201 14120400617 0015310 0 ustar 00root root 0000000 0000000 package main
import (
"flag"
"fmt"
)
func main() {
flag.Parse()
fmt.Println("Narg:", flag.NArg())
}
// Output:
// Narg: 0
yaegi-0.10.0/_test/foo-bar/ 0000775 0000000 0000000 00000000000 14120400617 0015324 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/foo-bar/foo-bar.go 0000664 0000000 0000000 00000000042 14120400617 0017174 0 ustar 00root root 0000000 0000000 package bar
var Name = "foo-bar"
yaegi-0.10.0/_test/foo/ 0000775 0000000 0000000 00000000000 14120400617 0014562 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/foo/bar.go 0000664 0000000 0000000 00000000206 14120400617 0015653 0 ustar 00root root 0000000 0000000 package foo
import "github.com/traefik/yaegi/_test/foo/boo"
var Bar = "BARR"
var Boo = boo.Boo
func init() { println("init foo") }
yaegi-0.10.0/_test/foo/bir.go 0000664 0000000 0000000 00000000127 14120400617 0015665 0 ustar 00root root 0000000 0000000 package foo
import "github.com/traefik/yaegi/_test/foo/boo"
var Bir = boo.Boo + "22"
yaegi-0.10.0/_test/foo/boo/ 0000775 0000000 0000000 00000000000 14120400617 0015341 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/foo/boo/boo.go 0000664 0000000 0000000 00000000102 14120400617 0016440 0 ustar 00root root 0000000 0000000 package boo
var Boo = "Boo"
func init() { println("init boo") }
yaegi-0.10.0/_test/for0.go 0000664 0000000 0000000 00000000235 14120400617 0015174 0 ustar 00root root 0000000 0000000 package main
func main() {
i := 0
//for ;i >= 0; i++ {
for {
if i > 5 {
break
}
println(i)
i++
}
}
// Output:
// 0
// 1
// 2
// 3
// 4
// 5
yaegi-0.10.0/_test/for1.go 0000664 0000000 0000000 00000000211 14120400617 0015167 0 ustar 00root root 0000000 0000000 package main
func main() {
i := 0
for i < 10 {
if i > 4 {
break
}
println(i)
i++
}
}
// Output:
// 0
// 1
// 2
// 3
// 4
yaegi-0.10.0/_test/for10.go 0000664 0000000 0000000 00000000174 14120400617 0015257 0 ustar 00root root 0000000 0000000 package main
func main() {
for a := 0; false; {
println("nok", a)
a++
break
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/for11.go 0000664 0000000 0000000 00000000211 14120400617 0015250 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 0
for ; true; a++ {
println("nok", a)
break
}
println("bye", a)
}
// Output:
// nok 0
// bye 0
yaegi-0.10.0/_test/for12.go 0000664 0000000 0000000 00000000172 14120400617 0015257 0 ustar 00root root 0000000 0000000 package main
func main() {
for a := 0; false; a++ {
println("nok", a)
break
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/for13.go 0000664 0000000 0000000 00000000201 14120400617 0015251 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 0
for ; false; a++ {
println("nok", a)
break
}
println("bye", a)
}
// Output:
// bye 0
yaegi-0.10.0/_test/for14.go 0000664 0000000 0000000 00000000216 14120400617 0015260 0 ustar 00root root 0000000 0000000 package main
func main() {
for a := 0; true; a++ {
println(a)
if a > 0 {
break
}
}
println("bye")
}
// Output:
// 0
// 1
// bye
yaegi-0.10.0/_test/for15.go 0000664 0000000 0000000 00000000256 14120400617 0015265 0 ustar 00root root 0000000 0000000 package main
func f() int { println("in f"); return 1 }
func main() {
for i := f(); ; {
println("in loop")
if i > 0 {
break
}
}
}
// Output:
// in f
// in loop
yaegi-0.10.0/_test/for16.go 0000664 0000000 0000000 00000000232 14120400617 0015260 0 ustar 00root root 0000000 0000000 package main
func main() {
max := 1
for ; ; max-- {
if max == 0 {
break
}
println("in for")
}
println("bye")
}
// Output:
// in for
// bye
yaegi-0.10.0/_test/for2.go 0000664 0000000 0000000 00000000170 14120400617 0015174 0 ustar 00root root 0000000 0000000 package main
func main() {
for i := 2; ; i++ {
println(i)
if i > 3 {
break
}
}
}
// Output:
// 2
// 3
// 4
yaegi-0.10.0/_test/for3.go 0000664 0000000 0000000 00000000616 14120400617 0015202 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"sort"
)
func main() {
m := map[string][]string{
"hello": []string{"foo", "bar"},
"world": []string{"truc", "machin"},
}
var content []string
for key, values := range m {
for _, value := range values {
content = append(content, key+value)
}
}
sort.Strings(content)
fmt.Println(content)
}
// Output:
// [hellobar hellofoo worldmachin worldtruc]
yaegi-0.10.0/_test/for4.go 0000664 0000000 0000000 00000000243 14120400617 0015177 0 ustar 00root root 0000000 0000000 package main
func main() {
for i := 1; i <= 2; i++ {
var x, y int
println(x, y)
x, y = i, 2*i
println(x, y)
}
}
// Output:
// 0 0
// 1 2
// 0 0
// 2 4
yaegi-0.10.0/_test/for5.go 0000664 0000000 0000000 00000000163 14120400617 0015201 0 ustar 00root root 0000000 0000000 package main
func main() {
var a bool
for a {
println("nok")
break
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/for6.go 0000664 0000000 0000000 00000000411 14120400617 0015176 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
s := "三"
for i := 0; i < len(s); i++ {
fmt.Printf("byte %d: %d\n", i, s[i])
}
for i, r := range s {
fmt.Printf("rune %d: %d\n", i, r)
}
}
// Output:
// byte 0: 228
// byte 1: 184
// byte 2: 137
// rune 0: 19977
yaegi-0.10.0/_test/for7.go 0000664 0000000 0000000 00000000146 14120400617 0015204 0 ustar 00root root 0000000 0000000 package main
func main() {
for i := 0; i; {
}
}
// Error:
// 4:14: non-bool used as for condition
yaegi-0.10.0/_test/for8.go 0000664 0000000 0000000 00000000226 14120400617 0015204 0 ustar 00root root 0000000 0000000 package main
func main() {
for i := 0; i < 4; i++ {
for {
break
}
if i == 1 {
continue
}
println(i)
}
}
// Output:
// 0
// 2
// 3
yaegi-0.10.0/_test/for9.go 0000664 0000000 0000000 00000000152 14120400617 0015203 0 ustar 00root root 0000000 0000000 package main
func main() {
for false {
println("nok")
break
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/fun.go 0000664 0000000 0000000 00000000144 14120400617 0015115 0 ustar 00root root 0000000 0000000 package main
func f(i int) int { return i + 15 }
func main() {
println(f(4))
}
// Output:
// 19
yaegi-0.10.0/_test/fun10.go 0000664 0000000 0000000 00000000310 14120400617 0015251 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f() func() {
return nil
}
func main() {
g := f()
fmt.Printf("%T %v\n", g, g)
if g == nil {
fmt.Println("nil func")
}
}
// Output:
// func()
// nil func
yaegi-0.10.0/_test/fun11.go 0000664 0000000 0000000 00000000132 14120400617 0015254 0 ustar 00root root 0000000 0000000 package main
var f F
type F func(int)
func main() {
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/fun12.go 0000664 0000000 0000000 00000000210 14120400617 0015252 0 ustar 00root root 0000000 0000000 package main
func use(interface{}) {}
func main() {
z := map[string]interface{}{"a": 5}
use(z)
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/fun13.go 0000664 0000000 0000000 00000000317 14120400617 0015263 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T struct{}
func newT() (T, error) { return T{}, nil }
func main() {
var (
i interface{}
err error
)
i, err = newT()
fmt.Println(i, err)
}
// Output:
// {}
yaegi-0.10.0/_test/fun14.go 0000664 0000000 0000000 00000000236 14120400617 0015264 0 ustar 00root root 0000000 0000000 package main
func f() (bool, int) { return true, 2 }
func g() (bool, int) { return f() }
func main() {
b, i := g()
println(b, i)
}
// Output:
// true 2
yaegi-0.10.0/_test/fun15.go 0000664 0000000 0000000 00000000316 14120400617 0015264 0 ustar 00root root 0000000 0000000 package main
func f1(a int) interface{} { return a + 1 }
func f2(a int64) interface{} { return a + 1 }
func main() {
c := f1(3)
println(c.(int))
b := f2(3)
println(b.(int64))
}
// Output:
// 4
// 4
yaegi-0.10.0/_test/fun16.go 0000664 0000000 0000000 00000000507 14120400617 0015267 0 ustar 00root root 0000000 0000000 package main
func f1(a int) int { return a + 1 }
func f2(a int) interface{} {
// TODO: re-enable the optimized case below, once we've figured out why it
// interferes with the empty interface model.
// return f1(a)
var foo interface{} = f1(a)
return foo
}
func main() {
c := f2(3)
println(c.(int))
}
// Output:
// 4
yaegi-0.10.0/_test/fun17.go 0000664 0000000 0000000 00000000247 14120400617 0015271 0 ustar 00root root 0000000 0000000 package main
func f1(a int) interface{} { return a + 1 }
func f2(a int) interface{} { return f1(a) }
func main() {
c := f2(3)
println(c.(int))
}
// Output:
// 4
yaegi-0.10.0/_test/fun18.go 0000664 0000000 0000000 00000000242 14120400617 0015265 0 ustar 00root root 0000000 0000000 package main
var m = map[string]int{"foo": 1, "bar": 2}
func f(s string) interface{} { return m[s] }
func main() {
println(f("foo").(int))
}
// Output:
// 1
yaegi-0.10.0/_test/fun19.go 0000664 0000000 0000000 00000000252 14120400617 0015267 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
func foo() ([]string, error) {
return nil, fmt.Errorf("bar")
}
func main() {
a, b := foo()
fmt.Println(a, b)
}
// Output:
// [] bar
yaegi-0.10.0/_test/fun2.go 0000664 0000000 0000000 00000000231 14120400617 0015174 0 ustar 00root root 0000000 0000000 package main
type Coord struct{ x, y int }
func f(c Coord) int { return c.x + c.y }
func main() {
c := Coord{3, 4}
println(f(c))
}
// Output:
// 7
yaegi-0.10.0/_test/fun20.go 0000664 0000000 0000000 00000000343 14120400617 0015260 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var myerr error = fmt.Errorf("bar")
func ferr() error { return myerr }
func foo() ([]string, error) {
return nil, ferr()
}
func main() {
a, b := foo()
fmt.Println(a, b)
}
// Output:
// [] bar
yaegi-0.10.0/_test/fun21.go 0000664 0000000 0000000 00000000177 14120400617 0015266 0 ustar 00root root 0000000 0000000 package main
func Bar() string {
return
}
func main() {
println(Bar())
}
// Error:
// 4:2: not enough arguments to return
yaegi-0.10.0/_test/fun22.go 0000664 0000000 0000000 00000000167 14120400617 0015266 0 ustar 00root root 0000000 0000000 package main
import "time"
func main() {
time.Date()
}
// Error:
// 6:2: not enough arguments in call to time.Date
yaegi-0.10.0/_test/fun23.go 0000664 0000000 0000000 00000000173 14120400617 0015264 0 ustar 00root root 0000000 0000000 package main
func f(x int) { return x }
func main() {
print("hello")
}
// Error:
// 3:17: too many arguments to return
yaegi-0.10.0/_test/fun24.go 0000664 0000000 0000000 00000000252 14120400617 0015263 0 ustar 00root root 0000000 0000000 package main
func f(x int) (int, int) { return x, "foo" }
func main() {
print("hello")
}
// Error:
// cannot use "foo" (type stringT) as type intT in return argument
yaegi-0.10.0/_test/fun25.go 0000664 0000000 0000000 00000000251 14120400617 0015263 0 ustar 00root root 0000000 0000000 package main
func f(x string) (a int, b int) { return x, 5 }
func main() {
print("hello")
}
// Error:
// cannot use x (type stringT) as type intT in return argument
yaegi-0.10.0/_test/fun26.go 0000664 0000000 0000000 00000000307 14120400617 0015266 0 ustar 00root root 0000000 0000000 package main
type F func() (int, error)
func f1() (int, error) { return 3, nil }
func f2(a string, f F) {
c, _ := f()
println(a, c)
}
func main() {
f2("hello", F(f1))
}
// Output:
// hello 3
yaegi-0.10.0/_test/fun27.go 0000664 0000000 0000000 00000000342 14120400617 0015266 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"sync"
)
func main() {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
print("test")
}()
wg.Wait()
}
func print(state string) {
fmt.Println(state)
}
// Output:
// test
yaegi-0.10.0/_test/fun3.go 0000664 0000000 0000000 00000000256 14120400617 0015204 0 ustar 00root root 0000000 0000000 package main
type Coord struct{ x, y int }
func f(i, j int, c Coord) int { return i*c.x + j*c.y }
func main() {
c := Coord{3, 4}
println(f(2, 3, c))
}
// Output:
// 18
yaegi-0.10.0/_test/fun4.go 0000664 0000000 0000000 00000000121 14120400617 0015174 0 ustar 00root root 0000000 0000000 package main
func f() {}
func main() {
f()
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/fun5.go 0000664 0000000 0000000 00000000130 14120400617 0015175 0 ustar 00root root 0000000 0000000 package main
func f(i int64) {
println(i)
}
func main() {
f(34)
}
// Output:
// 34
yaegi-0.10.0/_test/fun6.go 0000664 0000000 0000000 00000000306 14120400617 0015203 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"sync"
)
func NewPool() Pool { return Pool{} }
type Pool struct {
p *sync.Pool
}
var _pool = NewPool()
func main() {
fmt.Println(_pool)
}
// Output:
// {}
yaegi-0.10.0/_test/fun7.go 0000664 0000000 0000000 00000000260 14120400617 0015203 0 ustar 00root root 0000000 0000000 package main
import (
goflag "flag"
"fmt"
)
func Foo(goflag *goflag.Flag) {
fmt.Println(goflag)
}
func main() {
g := &goflag.Flag{}
Foo(g)
}
// Output:
// &{ }
yaegi-0.10.0/_test/fun8.go 0000664 0000000 0000000 00000000122 14120400617 0015201 0 ustar 00root root 0000000 0000000 package main
func main() { println(f == nil) }
var f func()
// Output:
// true
yaegi-0.10.0/_test/fun9.go 0000664 0000000 0000000 00000000152 14120400617 0015205 0 ustar 00root root 0000000 0000000 package main
type T uint
func main() {
type myint int
var i = myint(1)
println(i)
}
// Output:
// 1
yaegi-0.10.0/_test/goto0.go 0000664 0000000 0000000 00000000216 14120400617 0015355 0 ustar 00root root 0000000 0000000 package main
func main() {
println("foo")
goto L1
println("Hello")
L1:
println("bar")
println("bye")
}
// Output:
// foo
// bar
// bye
yaegi-0.10.0/_test/goto1.go 0000664 0000000 0000000 00000000137 14120400617 0015360 0 ustar 00root root 0000000 0000000 package main
func main() {
if true {
goto here
}
here:
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/heap.go 0000664 0000000 0000000 00000001760 14120400617 0015247 0 ustar 00root root 0000000 0000000 // This example demonstrates an integer heap built using the heap interface.
package main
import (
"container/heap"
"fmt"
)
// An IntHeap is a min-heap of ints.
type IntHeap []int
func (h IntHeap) Len() int { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) {
// Push and Pop use pointer receivers because they modify the slice's length,
// not just its contents.
*h = append(*h, x.(int))
}
func (h *IntHeap) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
*h = old[0 : n-1]
return x
}
// This example inserts several ints into an IntHeap, checks the minimum,
// and removes them in order of priority.
func main() {
h := &IntHeap{2, 1, 5}
heap.Init(h)
heap.Push(h, 3)
fmt.Printf("minimum: %d\n", (*h)[0])
fmt.Println("h:", h)
for h.Len() > 0 {
fmt.Printf("%d ", heap.Pop(h))
}
}
// Output:
// minimum: 1
// h: &[1 2 5 3]
// 1 2 3 5
yaegi-0.10.0/_test/if.go 0000664 0000000 0000000 00000000160 14120400617 0014721 0 ustar 00root root 0000000 0000000 package main
func main() {
if a := f(); a > 0 {
println(a)
}
}
func f() int { return 1 }
// Output:
// 1
yaegi-0.10.0/_test/if0.go 0000664 0000000 0000000 00000000164 14120400617 0015005 0 ustar 00root root 0000000 0000000 package main
func main() {
var a bool
if a {
println("ok")
} else {
println("nok")
}
}
// Output:
// nok
yaegi-0.10.0/_test/if1.go 0000664 0000000 0000000 00000000130 14120400617 0014777 0 ustar 00root root 0000000 0000000 package main
func main() {
i := 1
if i > 0 {
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/if2.go 0000664 0000000 0000000 00000000223 14120400617 0015003 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var i int
if i % 1000000 {
fmt.Println("oops")
}
}
// Error:
// 7:5: non-bool used as if condition
yaegi-0.10.0/_test/if3.go 0000664 0000000 0000000 00000000233 14120400617 0015005 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 0
if false {
println("false")
a = 1
} else {
println("true")
a = -1
}
println(a)
}
// Output:
// true
// -1
yaegi-0.10.0/_test/if4.go 0000664 0000000 0000000 00000000254 14120400617 0015011 0 ustar 00root root 0000000 0000000 package main
const bad = false
func main() {
a := 0
if bad {
println("false")
a = 1
} else {
println("true")
a = -1
}
println(a)
}
// Output:
// true
// -1
yaegi-0.10.0/_test/if5.go 0000664 0000000 0000000 00000000145 14120400617 0015011 0 ustar 00root root 0000000 0000000 package main
func main() {
if true {
println("ok")
}
println("bye")
}
// Output:
// ok
// bye
yaegi-0.10.0/_test/if6.go 0000664 0000000 0000000 00000000141 14120400617 0015006 0 ustar 00root root 0000000 0000000 package main
func main() {
if false {
println("nok")
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/if7.go 0000664 0000000 0000000 00000000170 14120400617 0015011 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 0
b := false
if (b) {
a = 1
} else {
a = -1
}
println(a)
}
// Output:
// -1
yaegi-0.10.0/_test/imag0.go 0000664 0000000 0000000 00000000253 14120400617 0015323 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f(c complex128) interface{} { return imag(c) }
func main() {
c := complex(3, 2)
a := f(c)
fmt.Println(a.(float64))
}
// Output:
// 2
yaegi-0.10.0/_test/import0.go 0000664 0000000 0000000 00000000136 14120400617 0015720 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
fmt.Println("Hello", 42)
}
// Output:
// Hello 42
yaegi-0.10.0/_test/import1.go 0000664 0000000 0000000 00000000136 14120400617 0015721 0 ustar 00root root 0000000 0000000 package main
import f "fmt"
func main() {
f.Println("Hello", 42)
}
// Output:
// Hello 42
yaegi-0.10.0/_test/import2.go 0000664 0000000 0000000 00000000134 14120400617 0015720 0 ustar 00root root 0000000 0000000 package main
import . "fmt"
func main() {
Println("Hello", 42)
}
// Output:
// Hello 42
yaegi-0.10.0/_test/import3.go 0000664 0000000 0000000 00000000225 14120400617 0015722 0 ustar 00root root 0000000 0000000 package main
import "github.com/traefik/yaegi/_test/foo"
func main() { println(foo.Bar, foo.Boo) }
// Output:
// init boo
// init foo
// BARR Boo
yaegi-0.10.0/_test/import4.go 0000664 0000000 0000000 00000000206 14120400617 0015722 0 ustar 00root root 0000000 0000000 package main
import "github.com/traefik/yaegi/_test/p1"
func main() { println("num:", p1.Uint32()) }
// Output:
// num: 2596996162
yaegi-0.10.0/_test/import5.go 0000664 0000000 0000000 00000000250 14120400617 0015722 0 ustar 00root root 0000000 0000000 package main
import boo "github.com/traefik/yaegi/_test/foo"
func main() { println(boo.Bar, boo.Boo, boo.Bir) }
// Output:
// init boo
// init foo
// BARR Boo Boo22
yaegi-0.10.0/_test/import6.go 0000664 0000000 0000000 00000000256 14120400617 0015731 0 ustar 00root root 0000000 0000000 package main
import "github.com/traefik/yaegi/_test/c1"
func main() {
println(c1.C1)
}
// Error:
// import cycle not allowed
// imports github.com/traefik/yaegi/_test/c1
yaegi-0.10.0/_test/import7.go 0000664 0000000 0000000 00000000175 14120400617 0015732 0 ustar 00root root 0000000 0000000 package main
import bar "github.com/traefik/yaegi/_test/foo-bar"
func main() {
println(bar.Name)
}
// Output:
// foo-bar
yaegi-0.10.0/_test/import8.go 0000664 0000000 0000000 00000000172 14120400617 0015730 0 ustar 00root root 0000000 0000000 package main
import "github.com/traefik/yaegi/_test/b1/foo"
func main() {
println(foo.Desc)
}
// Output:
// in b1/foo
yaegi-0.10.0/_test/import9.go 0000664 0000000 0000000 00000000171 14120400617 0015730 0 ustar 00root root 0000000 0000000 package main
import "github.com/traefik/yaegi/_test/baz-bat"
func main() {
println(baz.Name)
}
// Output:
// baz-bat
yaegi-0.10.0/_test/inc.go 0000664 0000000 0000000 00000000125 14120400617 0015075 0 ustar 00root root 0000000 0000000 package main
func main() {
i := 2
//i++
i = i + 1
println(i)
}
// Output:
// 3
yaegi-0.10.0/_test/inception.go 0000664 0000000 0000000 00000000674 14120400617 0016325 0 ustar 00root root 0000000 0000000 package main
import (
"log"
"github.com/traefik/yaegi/interp"
)
func main() {
log.SetFlags(log.Lshortfile)
i := interp.New(interp.Options{})
i.Use(interp.Symbols)
if _, err := i.Eval(`import "github.com/traefik/yaegi/interp"`); err != nil {
log.Fatal(err)
}
if _, err := i.Eval(`i := interp.New(interp.Options{})`); err != nil {
log.Fatal(err)
}
if _, err := i.Eval(`i.Eval("println(42)")`); err != nil {
log.Fatal(err)
}
}
yaegi-0.10.0/_test/init0.go 0000664 0000000 0000000 00000000341 14120400617 0015347 0 ustar 00root root 0000000 0000000 package main
func init() {
println("Hello from init 1")
}
func init() {
println("Hello from init 2")
}
func main() {
println("Hello from main")
}
// Output:
// Hello from init 1
// Hello from init 2
// Hello from main
yaegi-0.10.0/_test/init1.go 0000664 0000000 0000000 00000000172 14120400617 0015352 0 ustar 00root root 0000000 0000000 package main
func init() {
println("here")
}
func main() {
init()
}
// Error:
// _test/init1.go:8:2: undefined: init
yaegi-0.10.0/_test/interface0.go 0000664 0000000 0000000 00000000345 14120400617 0016350 0 ustar 00root root 0000000 0000000 package main
type sample struct {
count int
}
func run(inf interface{}, name string) {
x := inf.(sample)
println(x.count, name)
}
func main() {
a := sample{2}
println(a.count)
run(a, "truc")
}
// Output:
// 2
// 2 truc
yaegi-0.10.0/_test/interface1.go 0000664 0000000 0000000 00000000535 14120400617 0016352 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type fii interface {
Hello()
}
type Boo struct {
Name string
}
func (b *Boo) Hello() {
fmt.Println("Hello", b)
fmt.Println(b.Name)
}
func inCall(foo fii) {
fmt.Println("inCall")
foo.Hello()
}
func main() {
fmt.Println("in")
boo := &Boo{"foo"}
inCall(boo)
}
// Output:
// in
// inCall
// Hello &{foo}
// foo
yaegi-0.10.0/_test/interface10.go 0000664 0000000 0000000 00000000162 14120400617 0016426 0 ustar 00root root 0000000 0000000 package main
type Edge interface {
ReverseEdge() Edge
}
func main() {
println("hello")
}
// Output:
// hello
yaegi-0.10.0/_test/interface11.go 0000664 0000000 0000000 00000000560 14120400617 0016431 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type Error interface {
error
Code() string
}
type MyError Error
type T struct {
Name string
}
func (t *T) Error() string { return "err: " + t.Name }
func (t *T) Code() string { return "code: " + t.Name }
func newT(s string) MyError { return &T{s} }
func main() {
t := newT("foo")
fmt.Println(t.Code())
}
// Output:
// code: foo
yaegi-0.10.0/_test/interface12.go 0000664 0000000 0000000 00000000260 14120400617 0016427 0 ustar 00root root 0000000 0000000 package main
type I1 interface {
Truc()
}
type T1 struct{}
func (T1) Truc() { println("in T1 truc") }
var x I1 = T1{}
func main() {
x.Truc()
}
// Output:
// in T1 truc
yaegi-0.10.0/_test/interface13.go 0000664 0000000 0000000 00000000430 14120400617 0016427 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
type X struct{}
func (X) Foo() int {
return 1
}
func (X) Bar() int {
return 2
}
type Foo interface {
Foo() int
}
type Bar interface {
Bar() int
}
func main() {
var x X
var i Foo = x
j := i.(Bar)
fmt.Println(j.Bar())
}
// Output:
// 2
yaegi-0.10.0/_test/interface14.go 0000664 0000000 0000000 00000000300 14120400617 0016424 0 ustar 00root root 0000000 0000000 package main
type T struct{}
func (t *T) Error() string { return "T: error" }
var invalidT = &T{}
func main() {
var err error
if err != invalidT {
println("ok")
}
}
// Output:
// ok
yaegi-0.10.0/_test/interface15.go 0000664 0000000 0000000 00000000471 14120400617 0016436 0 ustar 00root root 0000000 0000000 package main
type Fooer interface {
Foo() string
}
type Barer interface {
//fmt.Stringer
Fooer
Bar()
}
type T struct{}
func (t *T) Foo() string { return "T: foo" }
func (*T) Bar() { println("in bar") }
var t = &T{}
func main() {
var f Barer
if f != t {
println("ok")
}
}
// Output:
// ok
yaegi-0.10.0/_test/interface16.go 0000664 0000000 0000000 00000000434 14120400617 0016436 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type Barer interface {
fmt.Stringer
Bar()
}
type T struct{}
func (*T) String() string { return "T: nothing" }
func (*T) Bar() { println("in bar") }
var t = &T{}
func main() {
var f Barer
if f != t {
println("ok")
}
}
// Output:
// ok
yaegi-0.10.0/_test/interface17.go 0000664 0000000 0000000 00000000276 14120400617 0016443 0 ustar 00root root 0000000 0000000 package main
type T struct{}
func (t T) Error() string { return "T: error" }
var invalidT = T{}
func main() {
var err error
if err != invalidT {
println("ok")
}
}
// Output:
// ok
yaegi-0.10.0/_test/interface18.go 0000664 0000000 0000000 00000000356 14120400617 0016443 0 ustar 00root root 0000000 0000000 package main
type T struct{}
func (t *T) Error() string { return "T: error" }
func (*T) Foo() { println("foo") }
var invalidT = &T{}
func main() {
var err error
if err != invalidT {
println("ok")
}
}
// Output:
// ok
yaegi-0.10.0/_test/interface19.go 0000664 0000000 0000000 00000000167 14120400617 0016444 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var I interface{}
func main() {
fmt.Printf("%T %v\n", I, I)
}
// Output:
//
yaegi-0.10.0/_test/interface2.go 0000664 0000000 0000000 00000000755 14120400617 0016357 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type fii interface {
Hello()
}
type Boo struct {
Name string
}
type Bar struct{}
func (b Bar) Hello() { fmt.Println("b:", b) }
func (b Boo) Hello() {
fmt.Println("Hello", b)
fmt.Println(b.Name)
}
func inCall(foo fii) {
fmt.Println("inCall")
switch a := foo.(type) {
case Boo:
a.Hello()
default:
fmt.Println("a:", a)
}
}
func main() {
boo := Boo{"foo"}
inCall(boo)
inCall(Bar{})
}
// Output:
// inCall
// Hello {foo}
// foo
// inCall
// a: {}
yaegi-0.10.0/_test/interface20.go 0000664 0000000 0000000 00000000161 14120400617 0016426 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a interface{}
a = string("A")
fmt.Println(a)
}
// Output:
// A
yaegi-0.10.0/_test/interface21.go 0000664 0000000 0000000 00000000167 14120400617 0016435 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
s := make([]interface{}, 1)
s[0] = 1
fmt.Println(s[0])
}
// Output:
// 1
yaegi-0.10.0/_test/interface22.go 0000664 0000000 0000000 00000000177 14120400617 0016437 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
s := make([]interface{}, 0)
s = append(s, 1)
fmt.Println(s[0])
}
// Output:
// 1
yaegi-0.10.0/_test/interface23.go 0000664 0000000 0000000 00000000213 14120400617 0016427 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
m := make(map[string]interface{})
m["A"] = string("A")
fmt.Println(m["A"])
}
// Output:
// A
yaegi-0.10.0/_test/interface24.go 0000664 0000000 0000000 00000000171 14120400617 0016433 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
m := make(map[string]interface{})
fmt.Println(m["B"])
}
// Output:
//
yaegi-0.10.0/_test/interface25.go 0000664 0000000 0000000 00000000227 14120400617 0016436 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
m := make(map[string]interface{})
m["A"] = 1
for _, v := range m {
fmt.Println(v)
}
}
// Output:
// 1
yaegi-0.10.0/_test/interface26.go 0000664 0000000 0000000 00000000227 14120400617 0016437 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
s := make([]interface{}, 0)
s = append(s, 1)
for _, v := range s {
fmt.Println(v)
}
}
// Output:
// 1
yaegi-0.10.0/_test/interface27.go 0000664 0000000 0000000 00000000175 14120400617 0016442 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var errs = map[int]error{0: nil}
func main() {
fmt.Println(errs)
}
// Output:
// map[0:]
yaegi-0.10.0/_test/interface28.go 0000664 0000000 0000000 00000000157 14120400617 0016443 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var errs = []error{nil}
func main() {
fmt.Println(errs)
}
// Output:
// []
yaegi-0.10.0/_test/interface29.go 0000664 0000000 0000000 00000000130 14120400617 0016433 0 ustar 00root root 0000000 0000000 package main
func main() {
var a interface{}
println(a == nil)
}
// Output:
// true
yaegi-0.10.0/_test/interface3.go 0000664 0000000 0000000 00000000501 14120400617 0016345 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type fii interface {
Hello()
}
type Boo struct {
Name string
}
func (b Boo) Hello() {
fmt.Println("Hello", b)
fmt.Println(b.Name)
}
func inCall(foo fii) {
fmt.Println("inCall")
foo.Hello()
}
func main() {
boo := Boo{"foo"}
inCall(boo)
}
// Output:
// inCall
// Hello {foo}
// foo
yaegi-0.10.0/_test/interface30.go 0000664 0000000 0000000 00000000131 14120400617 0016424 0 ustar 00root root 0000000 0000000 package main
func main() {
var a interface{}
println(a != nil)
}
// Output:
// false
yaegi-0.10.0/_test/interface31.go 0000664 0000000 0000000 00000000172 14120400617 0016432 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
s := []interface{}{"test", 2}
fmt.Println(s[0], s[1])
}
// Output:
// test 2
yaegi-0.10.0/_test/interface32.go 0000664 0000000 0000000 00000000173 14120400617 0016434 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
s := [2]interface{}{"test", 2}
fmt.Println(s[0], s[1])
}
// Output:
// test 2
yaegi-0.10.0/_test/interface33.go 0000664 0000000 0000000 00000000210 14120400617 0016425 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a = map[string]interface{}{"test": "test"}
fmt.Println(a["test"])
}
// Output:
// test
yaegi-0.10.0/_test/interface34.go 0000664 0000000 0000000 00000000201 14120400617 0016426 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
s := [2]interface{}{1: "test", 0: 2}
fmt.Println(s[0], s[1])
}
// Output:
// 2 test
yaegi-0.10.0/_test/interface35.go 0000664 0000000 0000000 00000000204 14120400617 0016432 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T struct {
I interface{}
}
func main() {
t := T{"test"}
fmt.Println(t)
}
// Output:
// {test}
yaegi-0.10.0/_test/interface36.go 0000664 0000000 0000000 00000000577 14120400617 0016450 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var (
t *S
_ I = t
_ J = t
)
type S struct {
Name string
}
func (s *S) F() int { return len(s.Name) }
func (s *S) G() int { return s.F() }
func (s *S) Ri() I { return s }
func (s *S) Rj() J { return s }
type J interface {
I
G() int
Rj() J
}
type I interface {
F() int
Ri() I
}
func main() {
var j J
fmt.Println(j)
}
// Output:
//
yaegi-0.10.0/_test/interface37.go 0000664 0000000 0000000 00000000411 14120400617 0016434 0 ustar 00root root 0000000 0000000 package main
type I interface {
A() string
B() string
}
type s struct{}
func NewS() (I, error) {
return &s{}, nil
}
func (c *s) A() string { return "a" }
func (c *s) B() string { return "b" }
func main() {
s, _ := NewS()
println(s.A())
}
// Output:
// a
yaegi-0.10.0/_test/interface38.go 0000664 0000000 0000000 00000000341 14120400617 0016437 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type foo struct {
bar string
}
func (f foo) String() string {
return "Hello from " + f.bar
}
func main() {
var f fmt.Stringer = foo{bar: "bar"}
fmt.Println(f)
}
// Output:
// Hello from bar
yaegi-0.10.0/_test/interface39.go 0000664 0000000 0000000 00000000343 14120400617 0016442 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type foo struct {
bar string
}
func (f *foo) String() string {
return "Hello from " + f.bar
}
func main() {
var f fmt.Stringer = &foo{bar: "bar"}
fmt.Println(f)
}
// Output:
// Hello from bar
yaegi-0.10.0/_test/interface4.go 0000664 0000000 0000000 00000000540 14120400617 0016351 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type fii interface {
Hello()
}
type Boo struct {
Name string
}
type Bir struct {
Boo
}
func (b Boo) Hello() {
fmt.Println("Hello", b)
fmt.Println(b.Name)
}
func inCall(foo fii) {
fmt.Println("inCall")
foo.Hello()
}
func main() {
bir := Bir{Boo{"foo"}}
inCall(bir)
}
// Output:
// inCall
// Hello {foo}
// foo
yaegi-0.10.0/_test/interface40.go 0000664 0000000 0000000 00000000400 14120400617 0016424 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type foo struct {
bar string
}
func (f foo) String() string {
return "Hello from " + f.bar
}
func Foo(s string) fmt.Stringer {
return foo{s}
}
func main() {
f := Foo("bar")
fmt.Println(f)
}
// Output:
// Hello from bar
yaegi-0.10.0/_test/interface41.go 0000664 0000000 0000000 00000000402 14120400617 0016427 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type foo struct {
bar string
}
func (f *foo) String() string {
return "Hello from " + f.bar
}
func Foo(s string) fmt.Stringer {
return &foo{s}
}
func main() {
f := Foo("bar")
fmt.Println(f)
}
// Output:
// Hello from bar
yaegi-0.10.0/_test/interface42.go 0000664 0000000 0000000 00000000143 14120400617 0016432 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
v := interface{}(0)
fmt.Println(v)
}
// Output:
// 0
yaegi-0.10.0/_test/interface43.go 0000664 0000000 0000000 00000000151 14120400617 0016432 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
v := interface{}(nil)
fmt.Println(v)
}
// Output:
//
yaegi-0.10.0/_test/interface44.go 0000664 0000000 0000000 00000000254 14120400617 0016437 0 ustar 00root root 0000000 0000000 package main
type S struct {
a int
}
func main() {
var i interface{} = S{a: 1}
s, ok := i.(S)
if !ok {
println("bad")
return
}
println(s.a)
}
// Output:
// 1
yaegi-0.10.0/_test/interface45.go 0000664 0000000 0000000 00000000212 14120400617 0016432 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var i interface{} = 1
var s struct{}
s, _ = i.(struct{})
fmt.Println(s)
}
// Output:
// {}
yaegi-0.10.0/_test/interface46.go 0000664 0000000 0000000 00000000513 14120400617 0016437 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type I interface {
Foo() string
}
type Printer struct {
i I
}
func New(i I) *Printer {
return &Printer{
i: i,
}
}
func (p *Printer) Print() {
fmt.Println(p.i.Foo())
}
type T struct{}
func (t *T) Foo() string {
return "test"
}
func main() {
g := New(&T{})
g.Print()
}
// Output:
// test
yaegi-0.10.0/_test/interface47.go 0000664 0000000 0000000 00000000564 14120400617 0016446 0 ustar 00root root 0000000 0000000 package main
type Doer interface {
Do() error
}
type T struct {
Name string
}
func (t *T) Do() error { println("in do"); return nil }
func f() (Doer, error) { return &T{"truc"}, nil }
type Ev struct {
doer func() (Doer, error)
}
func (e *Ev) do() {
d, _ := e.doer()
d.Do()
}
func main() {
e := &Ev{f}
println(e != nil)
e.do()
}
// Output:
// true
// in do
yaegi-0.10.0/_test/interface48.go 0000664 0000000 0000000 00000000235 14120400617 0016442 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type I1 interface{ A }
type A = I2
type I2 interface{ F() I1 }
func main() {
var i I1
fmt.Println(i)
}
// Output:
//
yaegi-0.10.0/_test/interface49.go 0000664 0000000 0000000 00000001274 14120400617 0016447 0 ustar 00root root 0000000 0000000 package main
type Descriptor interface {
ParentFile() FileDescriptor
}
type FileDescriptor interface {
Enums() EnumDescriptors
Services() ServiceDescriptors
}
type EnumDescriptors interface {
Get(i int) EnumDescriptor
}
type EnumDescriptor interface {
Values() EnumValueDescriptors
}
type EnumValueDescriptors interface {
Get(i int) EnumValueDescriptor
}
type EnumValueDescriptor interface {
Descriptor
}
type ServiceDescriptors interface {
Get(i int) ServiceDescriptor
}
type ServiceDescriptor interface {
Descriptor
isServiceDescriptor
}
type isServiceDescriptor interface{ ProtoType(ServiceDescriptor) }
func main() {
var d Descriptor
println(d == nil)
}
// Output:
// true
yaegi-0.10.0/_test/interface5.go 0000664 0000000 0000000 00000000353 14120400617 0016354 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type Myint int
func (i Myint) Double() { fmt.Println("Myint:", i, i) }
type Boo interface {
Double()
}
func f(boo Boo) {
boo.Double()
}
func main() {
var i Myint = 3
f(i)
}
// Output:
// Myint: 3 3
yaegi-0.10.0/_test/interface50.go 0000664 0000000 0000000 00000000215 14120400617 0016431 0 ustar 00root root 0000000 0000000 package main
func main() {
a := true
var b interface{} = 5
println(b.(int))
b = a == true
println(b.(bool))
}
// Output:
// 5
// true
yaegi-0.10.0/_test/interface51.go 0000664 0000000 0000000 00000000500 14120400617 0016427 0 ustar 00root root 0000000 0000000 package main
type Error interface {
error
Message() string
}
type T struct {
Msg string
}
func (t *T) Error() string { return t.Msg }
func (t *T) Message() string { return "message:" + t.Msg }
func newError() Error { return &T{"test"} }
func main() {
e := newError()
println(e.Error())
}
// Output:
// test
yaegi-0.10.0/_test/interface52.go 0000664 0000000 0000000 00000000272 14120400617 0016436 0 ustar 00root root 0000000 0000000 package main
import "testing"
func main() {
t := testing.T{}
var tb testing.TB
tb = &t
if tb.TempDir() == "" {
println("FAIL")
return
}
println("PASS")
}
// Output:
// PASS
yaegi-0.10.0/_test/interface6.go 0000664 0000000 0000000 00000000403 14120400617 0016351 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type Myint int
func (i Myint) Double() { fmt.Println("Myint:", i, i) }
type Boo interface {
Double()
}
func f(boo Boo) { boo.Double() }
func g(i int) Boo { return Myint(i) }
func main() {
f(g(4))
}
// Output:
// Myint: 4 4
yaegi-0.10.0/_test/interface7.go 0000664 0000000 0000000 00000000364 14120400617 0016360 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T int
func (t T) Error() string { return fmt.Sprintf("This is an error from T: %d", t) }
func f(t T) error { return t }
func main() {
x := T(1)
fmt.Println(f(x))
}
// Output:
// This is an error from T: 1
yaegi-0.10.0/_test/interface8.go 0000664 0000000 0000000 00000000403 14120400617 0016353 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
var _ = (HelloInterface)((*Hello)(nil))
type HelloInterface interface {
Hi() string
}
type Hello struct{}
func (h *Hello) Hi() string {
return "hi"
}
func main() {
h := &Hello{}
fmt.Println(h.Hi())
}
// Output:
// hi
yaegi-0.10.0/_test/interface9.go 0000664 0000000 0000000 00000000273 14120400617 0016361 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type Int int
func (I Int) String() string {
return "foo"
}
func main() {
var i Int
var st fmt.Stringer = i
fmt.Println(st.String())
}
// Output:
// foo
yaegi-0.10.0/_test/interp.gi 0000664 0000000 0000000 00000000235 14120400617 0015621 0 ustar 00root root 0000000 0000000 package main
import (
"github.com/traefik/yaegi/interp"
)
func main() {
i := interp.New(interp.Opt{})
i.Eval(`println("Hello")`)
}
// Output:
// Hello
yaegi-0.10.0/_test/interp2.gi 0000664 0000000 0000000 00000000452 14120400617 0015704 0 ustar 00root root 0000000 0000000 package main
import (
"github.com/traefik/yaegi/interp"
)
func main() {
i := interp.New(interp.Opt{})
i.Use(interp.ExportValue, interp.ExportType)
i.Eval(`import "github.com/traefik/yaegi/interp"`)
i.Eval(`i := interp.New(interp.Opt{})`)
i.Eval(`i.Eval("println(42)")`)
}
// Output:
// 42
yaegi-0.10.0/_test/io0.go 0000664 0000000 0000000 00000000277 14120400617 0015023 0 ustar 00root root 0000000 0000000 package main
import (
"crypto/rand"
"fmt"
"io"
)
func main() {
var buf [16]byte
fmt.Println(buf)
io.ReadFull(rand.Reader, buf[:])
//io.ReadFull(rand.Reader, buf)
fmt.Println(buf)
}
yaegi-0.10.0/_test/io1.go 0000664 0000000 0000000 00000000256 14120400617 0015021 0 ustar 00root root 0000000 0000000 package main
import (
"encoding/base64"
"fmt"
)
func main() {
var buf [4]byte
s := base64.RawStdEncoding.EncodeToString(buf[:])
fmt.Println(s)
}
// Output:
// AAAAAA
yaegi-0.10.0/_test/iota.go 0000664 0000000 0000000 00000000314 14120400617 0015260 0 ustar 00root root 0000000 0000000 package main
import "fmt"
const (
Foo = iota
Bar
Baz
)
const (
Asm = iota
C
Java
Go
)
func main() {
fmt.Println(Foo, Bar, Baz)
fmt.Println(Asm, C, Java, Go)
}
// Output:
// 0 1 2
// 0 1 2 3
yaegi-0.10.0/_test/iota0.go 0000664 0000000 0000000 00000000327 14120400617 0015344 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
const (
Foo = iota
Bar
Baz
)
const (
Asm = iota
C
Java
Go
)
fmt.Println(Foo, Bar, Baz)
fmt.Println(Asm, C, Java, Go)
}
// Output:
// 0 1 2
// 0 1 2 3
yaegi-0.10.0/_test/ioutil.go 0000664 0000000 0000000 00000000332 14120400617 0015631 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io/ioutil"
)
func main() {
_, err := ioutil.ReadFile("__NotExisting__")
if err != nil {
fmt.Println(err.Error())
}
}
// Output:
// open __NotExisting__: no such file or directory
yaegi-0.10.0/_test/ioutil0.go 0000664 0000000 0000000 00000000552 14120400617 0015715 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io/ioutil"
"log"
"strings"
)
func main() {
r := strings.NewReader("Go is a general-purpose language designed with systems programming in mind.")
b, err := ioutil.ReadAll(r)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s", b)
}
// Output:
// Go is a general-purpose language designed with systems programming in mind.
yaegi-0.10.0/_test/ipp_as_key.go 0000664 0000000 0000000 00000000427 14120400617 0016454 0 ustar 00root root 0000000 0000000 package main
import (
"guthib.com/toto" // pkg name is actually titi
"guthib.com/tata" // pkg name is actually tutu
)
func main() {
println("Hello", titi.Quux())
println("Hello", tutu.Quux())
}
// GOPATH:testdata/redeclaration-global7
// Output:
// Hello bar
// Hello baz
yaegi-0.10.0/_test/issue-1007.go 0000664 0000000 0000000 00000000630 14120400617 0016042 0 ustar 00root root 0000000 0000000 package main
type TypeA struct {
B TypeB
}
type TypeB struct {
C1 *TypeC
C2 *TypeC
}
type TypeC struct {
Val string
D *TypeD
D2 *TypeD
}
type TypeD struct {
Name string
}
func build() *TypeA {
return &TypeA{
B: TypeB{
C2: &TypeC{Val: "22"},
},
}
}
func Bar(s string) string {
a := build()
return s + "-" + a.B.C2.Val
}
func main() {
println(Bar("test"))
}
// Output:
// test-22
yaegi-0.10.0/_test/issue-1010.go 0000664 0000000 0000000 00000000561 14120400617 0016037 0 ustar 00root root 0000000 0000000 package main
import (
"encoding/json"
"fmt"
)
type MyJsonMarshaler struct{ n int }
func (m MyJsonMarshaler) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`{"num": %d}`, m.n)), nil
}
func main() {
ch := make(chan json.Marshaler, 1)
ch <- MyJsonMarshaler{2}
m, err := json.Marshal(<-ch)
fmt.Println(string(m), err)
}
// Output:
// {"num":2}
yaegi-0.10.0/_test/issue-1022.go 0000664 0000000 0000000 00000000246 14120400617 0016042 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
defer func() {
r := recover()
if r != nil {
fmt.Println(r)
}
}()
panic("Ho Ho Ho!")
}
// Output:
// Ho Ho Ho!
yaegi-0.10.0/_test/issue-1052.go 0000664 0000000 0000000 00000000273 14120400617 0016045 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a, b := 1, 1
for i := 0; i < 10; i++ {
fmt.Println(a)
a, b = b, a+b
}
}
// Output:
// 1
// 1
// 2
// 3
// 5
// 8
// 13
// 21
// 34
// 55
yaegi-0.10.0/_test/issue-1065.go 0000664 0000000 0000000 00000000440 14120400617 0016045 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type AST struct {
Num int
Children []AST
}
func newAST(num int, root AST, children ...AST) AST {
return AST{num, append([]AST{root}, children...)}
}
func main() {
ast := newAST(1, AST{}, AST{})
fmt.Println(ast)
}
// Output:
// {1 [{0 []} {0 []}]}
yaegi-0.10.0/_test/issue-1068.go 0000664 0000000 0000000 00000000262 14120400617 0016052 0 ustar 00root root 0000000 0000000 package main
type I interface {
Hello()
}
type T struct{}
func (t T) Hello() { println("hello") }
type I2 I
func main() {
var i I2 = T{}
i.Hello()
}
// Output:
// hello
yaegi-0.10.0/_test/issue-1088.go 0000664 0000000 0000000 00000000423 14120400617 0016053 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
for i, ch := range "日本語" {
fmt.Printf("%#U starts at byte position %d\n", ch, i)
}
}
// Output:
// U+65E5 '日' starts at byte position 0
// U+672C '本' starts at byte position 3
// U+8A9E '語' starts at byte position 6
yaegi-0.10.0/_test/issue-1089.go 0000664 0000000 0000000 00000000231 14120400617 0016051 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(`"` + time.RFC3339Nano + `"`)
}
// Output:
// "2006-01-02T15:04:05.999999999Z07:00"
yaegi-0.10.0/_test/issue-1093.go 0000664 0000000 0000000 00000000245 14120400617 0016051 0 ustar 00root root 0000000 0000000 package main
func b() string {
return "b"
}
func main() {
var x int
x = "a" + b()
}
// Error:
// 9:6: cannot use type untyped string as type int in assignment
yaegi-0.10.0/_test/issue-1094.go 0000664 0000000 0000000 00000000221 14120400617 0016044 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var x interface{}
x = "a" + fmt.Sprintf("b")
fmt.Printf("%v %T\n", x, x)
}
// Output:
// ab string
yaegi-0.10.0/_test/issue-1101.go 0000664 0000000 0000000 00000000264 14120400617 0016040 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
func main() {
method := "POST"
switch method {
case http.MethodPost:
fmt.Println("It's a post!")
}
}
// Output:
// It's a post!
yaegi-0.10.0/_test/issue-1115.go 0000664 0000000 0000000 00000000412 14120400617 0016040 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
outer:
for y := 0; y < 10; y++ {
for x := 0; x < 10; x++ {
if x == 5 && y == 5 {
break outer
}
}
fmt.Println(y)
}
fmt.Println("Yay! I finished!")
}
// Output:
// 0
// 1
// 2
// 3
// 4
// Yay! I finished!
yaegi-0.10.0/_test/issue-1126.go 0000664 0000000 0000000 00000000421 14120400617 0016042 0 ustar 00root root 0000000 0000000 package main
import (
"errors"
"fmt"
"strings"
)
func main() {
err := errors.New("hello there")
switch true {
case err == nil:
break
case strings.Contains(err.Error(), "hello"):
fmt.Println("True!")
default:
fmt.Println("False!")
}
}
// Output:
// True!
yaegi-0.10.0/_test/issue-1128.go 0000664 0000000 0000000 00000000164 14120400617 0016050 0 ustar 00root root 0000000 0000000 package main
import "net"
func main() {
c := append(net.Buffers{}, []byte{})
println(len(c))
}
// Output:
// 1
yaegi-0.10.0/_test/issue-1134.go 0000664 0000000 0000000 00000000316 14120400617 0016044 0 ustar 00root root 0000000 0000000 package main
type I interface {
Hello()
}
type T struct {
Name string
Child []*T
}
func (t *T) Hello() { println("Hello", t.Name) }
func main() {
var i I = new(T)
i.Hello()
}
// Output:
// Hello
yaegi-0.10.0/_test/issue-1136.go 0000664 0000000 0000000 00000000425 14120400617 0016047 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io"
)
type T struct {
r io.Reader
}
func (t *T) Read(p []byte) (n int, err error) { n, err = t.r.Read(p); return }
func main() {
x := io.LimitedReader{}
y := io.Reader(&x)
y = &T{y}
fmt.Println(y.Read([]byte("")))
}
// Output:
// 0 EOF
yaegi-0.10.0/_test/issue-1145.go 0000664 0000000 0000000 00000000215 14120400617 0016044 0 ustar 00root root 0000000 0000000 package main
import "sync"
type F func()
func main() {
var wg sync.WaitGroup
var f F = wg.Done
println(f != nil)
}
// Output:
// true
yaegi-0.10.0/_test/issue-1156.go 0000664 0000000 0000000 00000000474 14120400617 0016055 0 ustar 00root root 0000000 0000000 package main
type myInterface interface {
myFunc() string
}
type V struct{}
func (v *V) myFunc() string { return "hello" }
type U struct {
v myInterface
}
func (u *U) myFunc() string { return u.v.myFunc() }
func main() {
x := V{}
y := myInterface(&x)
y = &U{y}
println(y.myFunc())
}
// Output:
// hello
yaegi-0.10.0/_test/issue-1163.go 0000664 0000000 0000000 00000001223 14120400617 0016044 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type WidgetEvent struct {
Nothing string
}
type WidgetControl interface {
HandleEvent(e *WidgetEvent)
}
type Button struct{}
func (b *Button) HandleEvent(e *WidgetEvent) {
}
type WindowEvent struct {
Something int
}
type Window struct {
Widget WidgetControl
}
func (w *Window) HandleEvent(e *WindowEvent) {
}
func main() {
window := &Window{
Widget: &Button{},
}
windowevent := &WindowEvent{}
// The next line uses the signature from the wrong method, resulting in an error.
// Renaming one of the clashing method names fixes the problem.
window.HandleEvent(windowevent)
fmt.Println("OK!")
}
// Output:
// OK!
yaegi-0.10.0/_test/issue-1166.go 0000664 0000000 0000000 00000000442 14120400617 0016051 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io"
)
type T []byte
func (t *T) Write(p []byte) (n int, err error) { *t = append(*t, p...); return len(p), nil }
func foo(w io.Writer) {
a := w.(*T)
fmt.Fprint(a, "test")
fmt.Printf("%s\n", *a)
}
func main() {
x := T{}
foo(&x)
}
// Output:
// test
yaegi-0.10.0/_test/issue-1167.go 0000664 0000000 0000000 00000000423 14120400617 0016051 0 ustar 00root root 0000000 0000000 package main
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
)
func main() {
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
panic(err)
}
pub := key.Public().(*ecdsa.PublicKey)
println(pub.Params().Name)
}
// Output:
// P-256
yaegi-0.10.0/_test/issue-1173.go 0000664 0000000 0000000 00000000143 14120400617 0016045 0 ustar 00root root 0000000 0000000 package main
var real = func() { println("Hello") }
func main() {
real()
}
// Output:
// Hello
yaegi-0.10.0/_test/issue-1175.go 0000664 0000000 0000000 00000000253 14120400617 0016051 0 ustar 00root root 0000000 0000000 package main
type Level int8
const (
a Level = -1
b Level = 5
d = b - a + 1
)
type counters [d]int
func main() {
println(len(counters{}))
}
// Output:
// 7
yaegi-0.10.0/_test/issue-1177.go 0000664 0000000 0000000 00000000207 14120400617 0016052 0 ustar 00root root 0000000 0000000 package main
type counters [3][16]int
func main() {
cs := &counters{}
p := &cs[0][1]
*p = 2
println(cs[0][1])
}
// Output:
// 2
yaegi-0.10.0/_test/issue-1179.go 0000664 0000000 0000000 00000000414 14120400617 0016054 0 ustar 00root root 0000000 0000000 package main
type I interface {
F()
}
type T struct {
Name string
}
func (t *T) F() { println("in F", t.Name) }
func NewI(s string) I { return newT(s) }
func newT(s string) *T { return &T{s} }
func main() {
i := NewI("test")
i.F()
}
// Output:
// in F test
yaegi-0.10.0/_test/issue-1181.go 0000664 0000000 0000000 00000000135 14120400617 0016045 0 ustar 00root root 0000000 0000000 package main
func main() {
a, b := 1, 2
a, b = b, -a
println(a, b)
}
// Output:
// 2 -1
yaegi-0.10.0/_test/issue-1185.go 0000664 0000000 0000000 00000000341 14120400617 0016050 0 ustar 00root root 0000000 0000000 package main
import "io"
type B []byte
func (b B) Write(p []byte) (n int, err error) {
b = p
return len(p), nil
}
func main() {
b := B{}
a := make([]io.Writer, 0)
a = append(a, b)
println(len(a))
}
// Output:
// 1
yaegi-0.10.0/_test/issue-1187.go 0000664 0000000 0000000 00000001233 14120400617 0016053 0 ustar 00root root 0000000 0000000 package main
import (
"io"
"io/ioutil"
"os"
)
type sink interface {
io.Writer
io.Closer
}
func newSink() sink {
// return os.Stdout // Stdout is special in yaegi tests
file, err := ioutil.TempFile("", "yaegi-test.*")
if err != nil {
panic(err)
}
return file
}
func main() {
s := newSink()
n, err := s.Write([]byte("Hello\n"))
if err != nil {
panic(err)
}
var writer io.Writer = s
m, err := writer.Write([]byte("Hello\n"))
if err != nil {
panic(err)
}
var closer io.Closer = s
err = closer.Close()
if err != nil {
panic(err)
}
err = os.Remove(s.(*os.File).Name())
if err != nil {
panic(err)
}
println(m, n)
}
// Output:
// 6 6
yaegi-0.10.0/_test/issue-1189.go 0000664 0000000 0000000 00000000565 14120400617 0016064 0 ustar 00root root 0000000 0000000 package main
type I interface {
Foo() int
}
type S1 struct {
i int
}
func (s S1) Foo() int { return s.i }
type S2 struct{}
func (s *S2) Foo() int { return 42 }
func main() {
Is := map[string]I{
"foo": S1{21},
"bar": &S2{},
}
n := 0
for _, s := range Is {
n += s.Foo()
}
bar := "bar"
println(n, Is["foo"].Foo(), Is[bar].Foo())
}
// Output:
// 63 21 42
yaegi-0.10.0/_test/issue-1202.go 0000664 0000000 0000000 00000001247 14120400617 0016044 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type foobar struct {
callback func(string) func()
}
func cb(text string) func() {
return func() {
fmt.Println(text)
}
}
func main() {
// These ways of invoking it all work...
cb("Hi from inline callback!")()
asVarTest1 := cb("Hi from asVarTest1 callback!")
asVarTest1()
asVarTest2 := cb
asVarTest2("Hi from asVarTest2 callback!")()
// But inside a struct panics in yaegi...
asStructField := &foobar{callback: cb}
asStructField.callback("Hi from struct field callback!")() // <--- panics here
}
// Output:
// Hi from inline callback!
// Hi from asVarTest1 callback!
// Hi from asVarTest2 callback!
// Hi from struct field callback!
yaegi-0.10.0/_test/issue-1205.go 0000664 0000000 0000000 00000000454 14120400617 0016046 0 ustar 00root root 0000000 0000000 package main
type Option interface {
apply()
}
func f(opts ...Option) {
for _, opt := range opts {
opt.apply()
}
}
type T struct{}
func (t *T) apply() { println("in apply") }
func main() {
opt := []Option{&T{}}
f(opt[0]) // works
f(opt...) // fails
}
// Output:
// in apply
// in apply
yaegi-0.10.0/_test/issue-1208.go 0000664 0000000 0000000 00000000465 14120400617 0016053 0 ustar 00root root 0000000 0000000 package main
type Enabler interface {
Enabled() bool
}
type Logger struct {
core Enabler
}
func (log *Logger) GetCore() Enabler { return log.core }
type T struct{}
func (t *T) Enabled() bool { return true }
func main() {
base := &Logger{&T{}}
println(base.GetCore().Enabled())
}
// Output:
// true
yaegi-0.10.0/_test/issue-558.go 0000664 0000000 0000000 00000001476 14120400617 0016005 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"strings"
)
type readAutoCloser struct {
r io.ReadCloser
}
func (a readAutoCloser) Read(b []byte) (n int, err error) {
if a.r == nil {
return 0, io.EOF
}
n, err = a.r.Read(b)
if err == io.EOF {
a.Close()
}
return n, err
}
func (a readAutoCloser) Close() error {
if a.r == nil {
return nil
}
return a.r.(io.Closer).Close()
}
type pipe struct {
Reader readAutoCloser
}
func newReadAutoCloser(r io.Reader) readAutoCloser {
if _, ok := r.(io.Closer); !ok {
return readAutoCloser{ioutil.NopCloser(r)}
}
return readAutoCloser{r.(io.ReadCloser)}
}
func main() {
p := &pipe{}
p.Reader = newReadAutoCloser(strings.NewReader("test"))
b, err := ioutil.ReadAll(p.Reader)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(b))
}
// Output:
// test
yaegi-0.10.0/_test/issue-735.go 0000664 0000000 0000000 00000000674 14120400617 0016001 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"strconv"
)
var optionsG map[string]string
var roundG int = 30
func strToInt(s string, defaultValue int) int {
n, err := strconv.ParseInt(s, 10, 0)
if err != nil {
return defaultValue
}
return int(n)
}
func main() {
optionsG := map[string]string{"round": "12", "b": "one"}
roundG = strToInt(optionsG["round"], 50)
fmt.Println(roundG)
fmt.Println(optionsG)
}
// Output:
// 12
// map[b:one round:12]
yaegi-0.10.0/_test/issue-770.go 0000664 0000000 0000000 00000000404 14120400617 0015767 0 ustar 00root root 0000000 0000000 package main
import "reflect"
type I interface {
Foo() int
}
type T struct {
Name string
}
func (t T) Foo() int { return 0 }
func f(v reflect.Value) int {
i := v.Interface().(I)
return i.Foo()
}
func main() {
println("hello")
}
// Output:
// hello
yaegi-0.10.0/_test/issue-772.go 0000664 0000000 0000000 00000000540 14120400617 0015772 0 ustar 00root root 0000000 0000000 package main
import (
"log"
"os"
"text/template"
)
type Message struct {
Data string
}
func main() {
tmpl := template.New("name")
_, err := tmpl.Parse("{{.Data}}")
if err != nil {
log.Fatal(err)
}
err = tmpl.Execute(os.Stdout, Message{
Data: "Hello, World!!",
})
if err != nil {
log.Fatal(err)
}
}
// Output:
// Hello, World!!
yaegi-0.10.0/_test/issue-775.go 0000664 0000000 0000000 00000000363 14120400617 0016000 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http/httptest"
)
func main() {
recorder := httptest.NewRecorder()
recorder.Header().Add("Foo", "Bar")
for key, value := range recorder.Header() {
fmt.Println(key, value)
}
}
// Output:
// Foo [Bar]
yaegi-0.10.0/_test/issue-776.go 0000664 0000000 0000000 00000001002 14120400617 0015770 0 ustar 00root root 0000000 0000000 package main
import "fmt"
// Filter is a filter
type Filter interface {
Foo()
}
// GIFT is a gift
type GIFT struct {
Filters []Filter
}
// New is a new filter list
func New(filters ...Filter) *GIFT {
return &GIFT{
Filters: filters,
}
}
// List lists filters
func (g *GIFT) List() {
fmt.Printf("Hello from List!\n")
}
// MyFilter is one of the filters
type MyFilter struct{}
// Foo is a foo
func (f *MyFilter) Foo() {}
func main() {
g := New(&MyFilter{})
g.List()
}
// Output:
// Hello from List!
yaegi-0.10.0/_test/issue-782.go 0000664 0000000 0000000 00000000253 14120400617 0015774 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
from := uint32(2)
to := uint32(4)
b := a[from:to]
fmt.Print(b)
}
// Output:
// [3 4]
yaegi-0.10.0/_test/issue-784.go 0000664 0000000 0000000 00000001356 14120400617 0016003 0 ustar 00root root 0000000 0000000 package main
import "fmt"
// Filter is a filter interface
type Filter interface {
Bounds(srcBounds string) (dstBounds string)
}
// GIFT type
type GIFT struct {
Filters []Filter
}
// New creates a new filter list and initializes it with the given slice of filters.
func New(filters ...Filter) *GIFT {
return &GIFT{
Filters: filters,
}
}
// Bounds calculates the appropriate bounds for the result image after applying all the added filters.
func (g *GIFT) Bounds(srcBounds string) (dstBounds string) {
dstBounds = srcBounds
for _, f := range g.Filters {
dstBounds = f.Bounds(dstBounds)
}
return dstBounds
}
func main() {
var filters []Filter
bounds := "foo"
g := New(filters...)
fmt.Println(g.Bounds(bounds))
}
// Output:
// foo
yaegi-0.10.0/_test/issue-880.go 0000664 0000000 0000000 00000000513 14120400617 0015772 0 ustar 00root root 0000000 0000000 package main
import (
"bufio"
"bytes"
)
func main() {
var buf1 = make([]byte, 1024)
var buf2 []byte
buf1 = []byte("Hallo\nTest\nLine3")
s := bufio.NewScanner(bytes.NewReader(buf1))
for s.Scan() {
buf2 = append(buf2, append(s.Bytes(), []byte("\n")...)...)
}
print(string(buf2))
}
// Output:
// Hallo
// Test
// Line3
yaegi-0.10.0/_test/issue-981.go 0000664 0000000 0000000 00000000342 14120400617 0015774 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
dp := make(map[int]int)
dp[0] = 1
for i := 1; i < 10; i++ {
dp[i] = dp[i-1] + dp[i-2]
}
fmt.Printf("%v\n", dp)
}
// Output:
// map[0:1 1:1 2:2 3:3 4:5 5:8 6:13 7:21 8:34 9:55]
yaegi-0.10.0/_test/issue-993.go 0000664 0000000 0000000 00000000223 14120400617 0015775 0 ustar 00root root 0000000 0000000 package main
var m map[string]int64
func initVar() {
m = make(map[string]int64)
}
func main() {
initVar()
println(len(m))
}
// Output:
// 0
yaegi-0.10.0/_test/l2.go 0000664 0000000 0000000 00000000710 14120400617 0014641 0 ustar 00root root 0000000 0000000 package main
func main() {
for a := 0; a < 20000; a++ {
if (a & 0x8ff) == 0x800 {
println(a)
}
}
}
// Output:
// 2048
// 2304
// 2560
// 2816
// 3072
// 3328
// 3584
// 3840
// 6144
// 6400
// 6656
// 6912
// 7168
// 7424
// 7680
// 7936
// 10240
// 10496
// 10752
// 11008
// 11264
// 11520
// 11776
// 12032
// 14336
// 14592
// 14848
// 15104
// 15360
// 15616
// 15872
// 16128
// 18432
// 18688
// 18944
// 19200
// 19456
// 19712
// 19968
yaegi-0.10.0/_test/l3.go 0000664 0000000 0000000 00000000246 14120400617 0014646 0 ustar 00root root 0000000 0000000 package main
//func myprint(i int) { println(i) }
func main() {
for a := 0; a < 20000000; a++ {
if a&0x8ffff == 0x80000 {
println(a)
//myprint(a)
}
}
}
yaegi-0.10.0/_test/l4.go 0000664 0000000 0000000 00000000146 14120400617 0014646 0 ustar 00root root 0000000 0000000 package main
func main() { println(f(5)) }
func f(i int) int { return i + 1 }
// Output:
// 6
yaegi-0.10.0/_test/l5.go 0000664 0000000 0000000 00000000236 14120400617 0014647 0 ustar 00root root 0000000 0000000 package main
//func myprint(i int) { println(i) }
func main() {
for a := 0; a < 20000000; {
if a&0x8ffff == 0x80000 {
println(a)
}
a = a + 1
}
}
yaegi-0.10.0/_test/len0.go 0000664 0000000 0000000 00000000206 14120400617 0015162 0 ustar 00root root 0000000 0000000 package main
func f(a []int) interface{} {
return len(a)
}
func main() {
a := []int{1, 2}
println(f(a).(int))
}
// Output:
// 2
yaegi-0.10.0/_test/m1/ 0000775 0000000 0000000 00000000000 14120400617 0014314 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/m1/main.go 0000664 0000000 0000000 00000000222 14120400617 0015563 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"testing"
)
func main() {
fmt.Println("vim-go")
}
func TestWeird(t *testing.T) {
fmt.Println("in TestWeird")
}
yaegi-0.10.0/_test/m1/main_test.go 0000664 0000000 0000000 00000000303 14120400617 0016622 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"testing"
)
func TestMain(t *testing.T) {
fmt.Println("in test")
}
func BenchmarkMain(b *testing.B) {
for i := 0; i < b.N; i++ {
rand.Int()
}
}
yaegi-0.10.0/_test/m2/ 0000775 0000000 0000000 00000000000 14120400617 0014315 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/m2/m2_test.go 0000664 0000000 0000000 00000000147 14120400617 0016223 0 ustar 00root root 0000000 0000000 package m2
import "testing"
func TestM2(t *testing.T) {
t.Errorf("got %s, want %s", "AAA", "BBB")
}
yaegi-0.10.0/_test/make.go 0000664 0000000 0000000 00000000203 14120400617 0015236 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
func main() {
h := make(http.Header)
fmt.Println("h:", h)
}
// Output:
// h: map[]
yaegi-0.10.0/_test/make0.go 0000664 0000000 0000000 00000000203 14120400617 0015316 0 ustar 00root root 0000000 0000000 package main
func f() interface{} {
return make([]int, 2)
}
func main() {
a := f()
println(len(a.([]int)))
}
// Output:
// 2
yaegi-0.10.0/_test/make1.go 0000664 0000000 0000000 00000000252 14120400617 0015323 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f() interface{} {
return make(map[int]int)
}
func main() {
a, ok := f().(map[int]int)
fmt.Println(a, ok)
}
// Output:
// map[] true
yaegi-0.10.0/_test/make2.go 0000664 0000000 0000000 00000000172 14120400617 0015325 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var s uint = 4
t := make([]int, s)
fmt.Println(t)
}
// Output:
// [0 0 0 0]
yaegi-0.10.0/_test/map.go 0000664 0000000 0000000 00000000225 14120400617 0015102 0 ustar 00root root 0000000 0000000 package main
type Dict map[string]string
func main() {
dict := make(Dict)
dict["truc"] = "machin"
println(dict["truc"])
}
// Output:
// machin
yaegi-0.10.0/_test/map10.go 0000664 0000000 0000000 00000000666 14120400617 0015254 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"sort"
)
type Foo struct {
Name string
}
func main() {
m := map[string][]Foo{
"hello": {Foo{"foo"}, Foo{"bar"}},
"world": {Foo{"truc"}, Foo{"machin"}},
}
var content []string
for key, values := range m {
for _, value := range values {
content = append(content, key+value.Name)
}
}
sort.Strings(content)
fmt.Println(content)
}
// Output:
// [hellobar hellofoo worldmachin worldtruc]
yaegi-0.10.0/_test/map11.go 0000664 0000000 0000000 00000000664 14120400617 0015253 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"sort"
)
type Foo struct {
Name string
}
func main() {
m := map[string][]Foo{
"hello": []Foo{{"foo"}, {"bar"}},
"world": []Foo{{"truc"}, {"machin"}},
}
var content []string
for key, values := range m {
for _, value := range values {
content = append(content, key+value.Name)
}
}
sort.Strings(content)
fmt.Println(content)
}
// Output:
// [hellobar hellofoo worldmachin worldtruc]
yaegi-0.10.0/_test/map12.go 0000664 0000000 0000000 00000000543 14120400617 0015250 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"sort"
)
type Foo struct {
Name string
}
func main() {
m := map[string]Foo{
"hello": {Name: "bar"},
"world": {Name: "machin"},
}
var content []string
for key, value := range m {
content = append(content, key+value.Name)
}
sort.Strings(content)
fmt.Println(content)
}
// Output:
// [hellobar worldmachin]
yaegi-0.10.0/_test/map13.go 0000664 0000000 0000000 00000000411 14120400617 0015243 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
const acceptEncoding = "Accept-Encoding"
func main() {
opts := &http.PushOptions{
Header: http.Header{
acceptEncoding: []string{"gzip"},
},
}
fmt.Println(opts)
}
// Output:
// &{ map[Accept-Encoding:[gzip]]}
yaegi-0.10.0/_test/map14.go 0000664 0000000 0000000 00000000274 14120400617 0015253 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var m = map[string]float64{"foo": 1.0}
func f(s string) bool { return m[s] > 0.0 }
func main() {
fmt.Println(f("foo"), f("bar"))
}
// Output:
// true false
yaegi-0.10.0/_test/map15.go 0000664 0000000 0000000 00000000210 14120400617 0015242 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
users := make(map[string]string)
v := users["a"]
fmt.Println("v:", v)
}
// Output:
// v:
yaegi-0.10.0/_test/map16.go 0000664 0000000 0000000 00000000416 14120400617 0015253 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
users := make(map[string]string)
v, exists := users["a"]
fmt.Println(v, exists)
if exists == true {
//if exists {
fmt.Println("exists", v)
} else {
fmt.Println("not exists")
}
}
// Output:
// false
// not exists
yaegi-0.10.0/_test/map17.go 0000664 0000000 0000000 00000000375 14120400617 0015260 0 ustar 00root root 0000000 0000000 package main
import "net/http"
type T struct {
header string
}
func (b *T) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if b.header != "" {
req.Header[b.header] = []string{"hello"}
}
}
func main() {
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/map18.go 0000664 0000000 0000000 00000000204 14120400617 0015250 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var foo = make([]int, 1)
func main() {
for _, v := range foo {
fmt.Println(v)
}
}
// Output:
// 0
yaegi-0.10.0/_test/map19.go 0000664 0000000 0000000 00000000263 14120400617 0015256 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type cmap struct {
servers map[int64]*server
}
type server struct {
cm *cmap
}
func main() {
m := cmap{}
fmt.Println(m)
}
// Output:
// {map[]}
yaegi-0.10.0/_test/map2.go 0000664 0000000 0000000 00000000205 14120400617 0015162 0 ustar 00root root 0000000 0000000 package main
func main() {
dict := make(map[string]string)
dict["truc"] = "machin"
println(dict["truc"])
}
// Output:
// machin
yaegi-0.10.0/_test/map20.go 0000664 0000000 0000000 00000000161 14120400617 0015243 0 ustar 00root root 0000000 0000000 package main
var a = map[int]bool{1: true, 2: true}
func main() {
println(a[1] && true)
}
// Output:
// true
yaegi-0.10.0/_test/map21.go 0000664 0000000 0000000 00000000215 14120400617 0015244 0 ustar 00root root 0000000 0000000 package main
var m = map[int]string{
1: "foo",
}
func main() {
var ok bool
if _, ok = m[1]; ok {
println("ok")
}
}
// Output:
// ok
yaegi-0.10.0/_test/map22.go 0000664 0000000 0000000 00000000176 14120400617 0015253 0 ustar 00root root 0000000 0000000 package main
var m = map[int]string{
1: "foo",
}
func main() {
var s string
s, _ = m[1]
println(s)
}
// Output:
// foo
yaegi-0.10.0/_test/map23.go 0000664 0000000 0000000 00000000162 14120400617 0015247 0 ustar 00root root 0000000 0000000 package main
var m = map[int]string{
1: "foo",
}
func main() {
_, _ = m[1]
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/map24.go 0000664 0000000 0000000 00000000455 14120400617 0015255 0 ustar 00root root 0000000 0000000 package main
import (
"encoding/json"
"fmt"
)
func main() {
jb := []byte(`{"property": "test"}`)
params := map[string]interface{}{"foo": 1}
if err := json.Unmarshal(jb, ¶ms); err != nil {
panic("marshal failed.")
}
fmt.Println(params["foo"], params["property"])
}
// Output:
// 1 test
yaegi-0.10.0/_test/map25.go 0000664 0000000 0000000 00000000563 14120400617 0015256 0 ustar 00root root 0000000 0000000 package main
import (
"encoding/json"
"strconv"
)
func main() {
jb := []byte(`{"num": "2"}`)
params := map[string]interface{}{"foo": "1"}
if err := json.Unmarshal(jb, ¶ms); err != nil {
panic(err)
}
sum := 0
for _, v := range params {
i, err := strconv.Atoi(v.(string))
if err != nil {
panic(err)
}
sum += i
}
println(sum)
}
// Output:
// 3
yaegi-0.10.0/_test/map26.go 0000664 0000000 0000000 00000000213 14120400617 0015247 0 ustar 00root root 0000000 0000000 package main
var m = map[string]int{"foo": 1, "bar": 2}
func main() {
var a interface{} = m["foo"]
println(a.(int))
}
// Output:
// 1
yaegi-0.10.0/_test/map27.go 0000664 0000000 0000000 00000000467 14120400617 0015263 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"text/template"
)
type fm map[string]interface{}
type foo struct{}
func main() {
a := make(fm)
a["foo"] = &foo{}
fmt.Println(a["foo"])
b := make(template.FuncMap) // type FuncMap map[string]interface{}
b["foo"] = &foo{}
fmt.Println(b["foo"])
}
// Output:
// &{}
// &{}
yaegi-0.10.0/_test/map28.go 0000664 0000000 0000000 00000000342 14120400617 0015254 0 ustar 00root root 0000000 0000000 package main
import (
"net/url"
)
func main() {
value1 := url.Values{}
value1.Set("first", "v1")
value1.Set("second", "v2")
l := 0
for k, v := range value1 {
l += len(k) + len(v)
}
println(l)
}
// Output:
// 13
yaegi-0.10.0/_test/map29.go 0000664 0000000 0000000 00000000435 14120400617 0015260 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
type Item struct {
Object interface{}
Expiry time.Duration
}
func main() {
items := map[string]Item{}
items["test"] = Item{
Object: "test",
Expiry: time.Second,
}
item := items["test"]
fmt.Println(item)
}
// Output:
// {test 1s}
yaegi-0.10.0/_test/map3.go 0000664 0000000 0000000 00000000201 14120400617 0015157 0 ustar 00root root 0000000 0000000 package main
func main() {
dict := map[string]string{}
dict["truc"] = "machin"
println(dict["truc"])
}
// Output:
// machin
yaegi-0.10.0/_test/map30.go 0000664 0000000 0000000 00000000703 14120400617 0015246 0 ustar 00root root 0000000 0000000 package main
import "strings"
func f(s string) string { return "hello " + s }
func g(s string) string { return "hi " + s }
var methods = map[string]func(string) string{
"f": f,
"h": strings.ToLower,
}
func main() {
methods["i"] = strings.ToUpper
methods["g"] = g
println(methods["f"]("test"))
println(methods["g"]("test"))
println(methods["i"]("test"))
println(methods["h"]("TEST"))
}
// Output:
// hello test
// hi test
// TEST
// test
yaegi-0.10.0/_test/map4.go 0000664 0000000 0000000 00000000314 14120400617 0015165 0 ustar 00root root 0000000 0000000 package main
func main() {
dict := map[string]string{"bidule": "machin", "truc": "bidule"}
dict["hello"] = "bonjour"
println(dict["bidule"])
println(dict["hello"])
}
// Output:
// machin
// bonjour
yaegi-0.10.0/_test/map5.go 0000664 0000000 0000000 00000000346 14120400617 0015173 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
dict := map[string]string{"bidule": "machin", "truc": "bidule"}
r, ok := dict["xxx"]
fmt.Println(r, ok)
r, ok = dict["truc"]
fmt.Println(r, ok)
}
// Output:
// false
// bidule true
yaegi-0.10.0/_test/map6.go 0000664 0000000 0000000 00000000227 14120400617 0015172 0 ustar 00root root 0000000 0000000 package main
func main() {
dict := map[string]string{"bidule": "machin"}
for k, v := range dict {
println(k, v)
}
}
// Output:
// bidule machin
yaegi-0.10.0/_test/map7.go 0000664 0000000 0000000 00000000203 14120400617 0015165 0 ustar 00root root 0000000 0000000 package main
func main() {
dict := map[int32]int64{13: 733}
for k, v := range dict {
println(k, v)
}
}
// Output:
// 13 733
yaegi-0.10.0/_test/map8.go 0000664 0000000 0000000 00000000576 14120400617 0015203 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"sort"
)
func main() {
m := map[string][]string{
"hello": {"foo", "bar"},
"world": {"truc", "machin"},
}
var content []string
for key, values := range m {
for _, value := range values {
content = append(content, key+value)
}
}
sort.Strings(content)
fmt.Println(content)
}
// Output:
// [hellobar hellofoo worldmachin worldtruc]
yaegi-0.10.0/_test/map9.go 0000664 0000000 0000000 00000000652 14120400617 0015177 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"sort"
)
type Foo struct {
Name string
}
func main() {
m := map[string][]Foo{
"hello": {{"foo"}, {"bar"}},
"world": {{"truc"}, {"machin"}},
}
var content []string
for key, values := range m {
for _, value := range values {
content = append(content, key+value.Name)
}
}
sort.Strings(content)
fmt.Println(content)
}
// Output:
// [hellobar hellofoo worldmachin worldtruc]
yaegi-0.10.0/_test/math0.go 0000664 0000000 0000000 00000000153 14120400617 0015336 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(math.Cos(math.Pi))
}
// Output:
// -1
yaegi-0.10.0/_test/math1.go 0000664 0000000 0000000 00000000173 14120400617 0015341 0 ustar 00root root 0000000 0000000 package main
import "math"
func main() {
var f float32
if f < math.MaxFloat32 {
println("ok")
}
}
// Output:
// ok
yaegi-0.10.0/_test/math2.go 0000664 0000000 0000000 00000000166 14120400617 0015344 0 ustar 00root root 0000000 0000000 package main
const c uint64 = 2
func main() {
if c&(1<<(uint64(1))) > 0 {
println("yes")
}
}
// Output:
// yes
yaegi-0.10.0/_test/math3.go 0000664 0000000 0000000 00000000763 14120400617 0015350 0 ustar 00root root 0000000 0000000 package main
import (
"crypto/md5"
"fmt"
)
func md5Crypt(password, salt, magic []byte) []byte {
d := md5.New()
d.Write(password)
d.Write(magic)
d.Write(salt)
d2 := md5.New()
d2.Write(password)
d2.Write(salt)
for i, mixin := 0, d2.Sum(nil); i < len(password); i++ {
d.Write([]byte{mixin[i%16]})
}
return d.Sum(nil)
}
func main() {
b := md5Crypt([]byte("1"), []byte("2"), []byte("3"))
fmt.Println(b)
}
// Output:
// [187 141 73 89 101 229 33 106 226 63 117 234 117 149 230 21]
yaegi-0.10.0/_test/method.go 0000664 0000000 0000000 00000000256 14120400617 0015611 0 ustar 00root root 0000000 0000000 package main
type Coord struct {
x, y int
}
func (c Coord) dist() int { return c.x*c.x + c.y*c.y }
func main() {
o := Coord{3, 4}
println(o.dist())
}
// Output:
// 25
yaegi-0.10.0/_test/method0.go 0000664 0000000 0000000 00000000471 14120400617 0015670 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type Foo struct {
}
func (Foo) Call() {
fmt.Println("Foo Called")
}
type Bar struct {
Foo
}
type Baz struct {
Foo
}
func (Baz) Call() {
fmt.Println("Baz Called")
}
func main() {
Foo{}.Call()
Bar{}.Call()
Baz{}.Call()
}
// Output:
// Foo Called
// Foo Called
// Baz Called
yaegi-0.10.0/_test/method1.go 0000664 0000000 0000000 00000000323 14120400617 0015665 0 ustar 00root root 0000000 0000000 package main
type Sample struct {
Name string
}
func (s *Sample) foo(i int) {
println("in foo", s.Name, i)
}
func main() {
sample := Sample{"hello"}
s := &sample
s.foo(3)
}
// Output:
// in foo hello 3
yaegi-0.10.0/_test/method10.go 0000664 0000000 0000000 00000000321 14120400617 0015743 0 ustar 00root root 0000000 0000000 package main
const BlockSize = 8
type Cipher struct{}
func (c *Cipher) BlockSize() int { return BlockSize }
func main() {
println(BlockSize)
s := Cipher{}
println(s.BlockSize())
}
// Output:
// 8
// 8
yaegi-0.10.0/_test/method11.go 0000664 0000000 0000000 00000000363 14120400617 0015752 0 ustar 00root root 0000000 0000000 package main
func BlockSize() string { return "func" }
type Cipher struct{}
func (c *Cipher) BlockSize() string { return "method" }
func main() {
println(BlockSize())
s := Cipher{}
println(s.BlockSize())
}
// Output:
// func
// method
yaegi-0.10.0/_test/method12.go 0000664 0000000 0000000 00000000266 14120400617 0015755 0 ustar 00root root 0000000 0000000 package main
type Coord struct {
x, y int
}
func (c Coord) dist() int { return c.x*c.x + c.y*c.y }
func main() {
o := Coord{3, 4}
f := o.dist
println(f())
}
// Output:
// 25
yaegi-0.10.0/_test/method13.go 0000664 0000000 0000000 00000000345 14120400617 0015754 0 ustar 00root root 0000000 0000000 package main
type Coord struct {
x, y int
}
func (c Coord) dist() int { return c.x*c.x + c.y*c.y }
type Point struct {
Coord
z int
}
func main() {
o := Point{Coord{3, 4}, 5}
f := o.dist
println(f())
}
// Output:
// 25
yaegi-0.10.0/_test/method14.go 0000664 0000000 0000000 00000000257 14120400617 0015757 0 ustar 00root root 0000000 0000000 package main
func main() {
o := Coord{3, 4}
println(o.dist())
}
func (c *Coord) dist() int { return c.x*c.x + c.y*c.y }
type Coord struct {
x, y int
}
// Output:
// 25
yaegi-0.10.0/_test/method15.go 0000664 0000000 0000000 00000000257 14120400617 0015760 0 ustar 00root root 0000000 0000000 package main
type Coord struct {
x, y int
}
func (c Coord) dist() int { return c.x*c.x + c.y*c.y }
func main() {
o := &Coord{3, 4}
println(o.dist())
}
// Output:
// 25
yaegi-0.10.0/_test/method16.go 0000664 0000000 0000000 00000000403 14120400617 0015752 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
type Cheese struct {
property string
}
func (t *Cheese) Hello(param string) {
fmt.Printf("%+v %+v", t, param)
}
func main() {
(*Cheese).Hello(&Cheese{property: "value"}, "param")
}
// Output:
// &{Xproperty:value} param
yaegi-0.10.0/_test/method17.go 0000664 0000000 0000000 00000000656 14120400617 0015765 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
type MyTime struct {
time.Time
index int
}
func (m MyTime) Foo() {
minute := m.Minute()
fmt.Println("minute:", minute)
}
func (m *MyTime) Bar() {
second := m.Second()
fmt.Println("second:", second)
}
func main() {
t := MyTime{}
t.Time = time.Date(2009, time.November, 10, 23, 4, 5, 0, time.UTC)
t.Foo()
t.Bar()
(&t).Bar()
}
// Output:
// minute: 4
// second: 5
// second: 5
yaegi-0.10.0/_test/method18.go 0000664 0000000 0000000 00000000637 14120400617 0015765 0 ustar 00root root 0000000 0000000 package main
import (
"compress/gzip"
"fmt"
"net/http"
)
type GzipResponseWriter struct {
http.ResponseWriter
index int
gw *gzip.Writer
}
type GzipResponseWriterWithCloseNotify struct {
*GzipResponseWriter
}
func (w GzipResponseWriterWithCloseNotify) CloseNotify() <-chan bool {
return w.ResponseWriter.(http.CloseNotifier).CloseNotify()
}
func main() {
fmt.Println("hello")
}
// Output:
// hello
yaegi-0.10.0/_test/method19.go 0000664 0000000 0000000 00000000327 14120400617 0015762 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f() (string, error) {
err := fmt.Errorf("a nice error")
return "", err
}
func main() {
_, err := f()
if err != nil {
fmt.Println(err.Error())
}
}
// Output:
// a nice error
yaegi-0.10.0/_test/method2.go 0000664 0000000 0000000 00000000335 14120400617 0015671 0 ustar 00root root 0000000 0000000 package main
type Coord struct {
x, y int
}
func (c Coord) dist() int { return c.x*c.x + c.y*c.y }
type Point struct {
Coord
z int
}
func main() {
o := Point{Coord{3, 4}, 5}
println(o.dist())
}
// Output:
// 25
yaegi-0.10.0/_test/method20.go 0000664 0000000 0000000 00000000340 14120400617 0015745 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"sync"
)
type Hello struct {
mu sync.Mutex
}
func (h *Hello) Hi() string {
h.mu.Lock()
h.mu.Unlock()
return "hi"
}
func main() {
a := &Hello{}
fmt.Println(a.Hi())
}
// Output:
// hi
yaegi-0.10.0/_test/method21.go 0000664 0000000 0000000 00000000246 14120400617 0015753 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
type Hello struct{}
func (*Hello) Hi() string {
panic("implement me")
}
func main() {
fmt.Println(&Hello{})
}
// Output:
// &{}
yaegi-0.10.0/_test/method22.go 0000664 0000000 0000000 00000000262 14120400617 0015752 0 ustar 00root root 0000000 0000000 package main
func Bar() {
s := Obj.Foo()
println(s)
}
var Obj = &T{}
type T struct{}
func (t *T) Foo() bool { return t != nil }
func main() {
Bar()
}
// Output:
// true
yaegi-0.10.0/_test/method23.go 0000664 0000000 0000000 00000000324 14120400617 0015752 0 ustar 00root root 0000000 0000000 package main
func Bar() {
s := Obj.Foo()
println(s)
}
var Obj = NewT()
func NewT() *T { return &T{} }
type T struct{}
func (t *T) Foo() bool { return t != nil }
func main() {
Bar()
}
// Output:
// true
yaegi-0.10.0/_test/method24.go 0000664 0000000 0000000 00000000545 14120400617 0015760 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"sync"
)
type Pool struct {
p *sync.Pool
}
func (p Pool) Get() *Buffer { return &Buffer{} }
func NewPool() Pool { return Pool{} }
type Buffer struct {
bs []byte
pool Pool
}
var (
_pool = NewPool()
Get = _pool.Get
)
func main() {
fmt.Println(_pool)
fmt.Println(Get())
}
// Output:
// {}
// &{[] {}}
yaegi-0.10.0/_test/method25.go 0000664 0000000 0000000 00000000545 14120400617 0015761 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"sync"
)
func (p Pool) Get() *Buffer { return &Buffer{} }
func NewPool() Pool { return Pool{} }
type Buffer struct {
bs []byte
pool Pool
}
type Pool struct {
p *sync.Pool
}
var (
_pool = NewPool()
Get = _pool.Get
)
func main() {
fmt.Println(_pool)
fmt.Println(Get())
}
// Output:
// {}
// &{[] {}}
yaegi-0.10.0/_test/method26.go 0000664 0000000 0000000 00000000303 14120400617 0015752 0 ustar 00root root 0000000 0000000 package main
func NewT(name string) *T { return &T{name} }
var C = NewT("test")
func (t *T) f() { println(t == C) }
type T struct {
Name string
}
func main() {
C.f()
}
// Output:
// true
yaegi-0.10.0/_test/method27.go 0000664 0000000 0000000 00000000327 14120400617 0015761 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
type AuthenticatedRequest struct {
http.Request
Username string
}
func main() {
a := &AuthenticatedRequest{}
fmt.Println("ua:", a.UserAgent())
}
// Output:
// ua:
yaegi-0.10.0/_test/method28.go 0000664 0000000 0000000 00000000255 14120400617 0015762 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T struct {
Name string
}
func (T) create() *T {
return &T{"Hello"}
}
func main() {
fmt.Println(T{}.create())
}
// Output:
// &{Hello}
yaegi-0.10.0/_test/method29.go 0000664 0000000 0000000 00000000344 14120400617 0015762 0 ustar 00root root 0000000 0000000 package main
import (
"context"
"net"
)
var lookupHost = net.DefaultResolver.LookupHost
func main() {
res, err := lookupHost(context.Background(), "localhost")
println(len(res) > 0, err == nil)
}
// Output:
// true true
yaegi-0.10.0/_test/method3.go 0000664 0000000 0000000 00000000343 14120400617 0015671 0 ustar 00root root 0000000 0000000 package main
type Coord struct {
x, y int
}
func (c Coord) dist() int { return c.x*c.x + c.y*c.y }
type Point struct {
Coord
z int
}
func main() {
o := Point{Coord{3, 4}, 5}
println(o.Coord.dist())
}
// Output:
// 25
yaegi-0.10.0/_test/method30.go 0000664 0000000 0000000 00000000306 14120400617 0015750 0 ustar 00root root 0000000 0000000 package main
type T struct {
Name string
}
func (t *T) foo(a string) string {
return t.Name + a
}
var g = &T{"global"}
var f = g.foo
func main() {
println(f("-x"))
}
// Output:
// global-x
yaegi-0.10.0/_test/method31.go 0000664 0000000 0000000 00000000465 14120400617 0015757 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var db dbWrapper
type dbWrapper struct {
DB *cmap
}
func (d *dbWrapper) get() *cmap {
return d.DB
}
type cmap struct {
name string
}
func (c *cmap) f() {
fmt.Println("in f, c", c)
}
func main() {
db.DB = &cmap{name: "test"}
db.get().f()
}
// Output:
// in f, c &{test}
yaegi-0.10.0/_test/method32.go 0000664 0000000 0000000 00000000240 14120400617 0015747 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
func main() {
var a = []func(string){bar}
b := a[0]
b("bar")
}
func bar(a string) {
fmt.Println(a)
}
// Output:
// bar
yaegi-0.10.0/_test/method33.go 0000664 0000000 0000000 00000001057 14120400617 0015757 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
type T1 struct{}
func (t1 T1) f() {
fmt.Println("T1.f()")
}
func (t1 T1) g() {
fmt.Println("T1.g()")
}
type T2 struct {
T1
}
func (t2 T2) f() {
fmt.Println("T2.f()")
}
type I interface {
f()
}
func printType(i I) {
if t1, ok := i.(T1); ok {
println("T1 ok")
t1.f()
t1.g()
}
if t2, ok := i.(T2); ok {
println("T2 ok")
t2.f()
t2.g()
}
}
func main() {
println("T1")
printType(T1{})
println("T2")
printType(T2{})
}
// Output:
// T1
// T1 ok
// T1.f()
// T1.g()
// T2
// T2 ok
// T2.f()
// T1.g()
yaegi-0.10.0/_test/method34.go 0000664 0000000 0000000 00000000662 14120400617 0015761 0 ustar 00root root 0000000 0000000 package main
type Root struct {
Name string
}
type One struct {
Root
}
type Hi interface {
Hello() string
}
type Hey interface {
Hello() string
}
func (r *Root) Hello() string { return "Hello " + r.Name }
func main() {
// TODO(mpl): restore when type assertions work again.
// var one interface{} = &One{Root{Name: "test2"}}
var one Hey = &One{Root{Name: "test2"}}
println(one.(Hi).Hello())
}
// Output:
// Hello test2
yaegi-0.10.0/_test/method35.go 0000664 0000000 0000000 00000000263 14120400617 0015757 0 ustar 00root root 0000000 0000000 package main
import "strconv"
func main() {
var err error
_, err = strconv.Atoi("erwer")
if _, ok := err.(*strconv.NumError); ok {
println("here")
}
}
// Output:
// here
yaegi-0.10.0/_test/method36.go 0000664 0000000 0000000 00000000507 14120400617 0015761 0 ustar 00root root 0000000 0000000 package main
type I interface{ Hello() }
type T struct{ Name string }
func (t *T) Hello() { println("Hello", t.Name) }
type FT func(i I)
type ST struct{ Handler FT }
func newF() FT {
return func(i I) {
i.Hello()
}
}
func main() {
st := &ST{}
st.Handler = newF()
st.Handler(&T{"test"})
}
// Output:
// Hello test
yaegi-0.10.0/_test/method37.go 0000664 0000000 0000000 00000000326 14120400617 0015761 0 ustar 00root root 0000000 0000000 package main
import (
"net"
"os"
)
func writeBufs(bufs ...[]byte) error {
b := net.Buffers(bufs)
_, err := b.WriteTo(os.Stdout)
return err
}
func main() {
writeBufs([]byte("hello"))
}
// Output:
// hello
yaegi-0.10.0/_test/method4.go 0000664 0000000 0000000 00000000416 14120400617 0015673 0 ustar 00root root 0000000 0000000 package main
type Coord struct {
x, y int
}
func (c Coord) dist() int { return c.x*c.x + c.y*c.y }
type Point struct {
Coord
z int
}
type Tpoint struct {
t int
Point
}
func main() {
o := Tpoint{0, Point{Coord{3, 4}, 5}}
println(o.dist())
}
// Output:
// 25
yaegi-0.10.0/_test/method5.go 0000664 0000000 0000000 00000000705 14120400617 0015675 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type Foo struct {
}
func (Foo) Show() {
fmt.Println("Foo Showed")
}
func (f Foo) Call() {
fmt.Println("Foo Called")
f.Show()
}
type Bar struct {
Foo
}
type Baz struct {
Foo
}
func (Baz) Call() {
fmt.Println("Baz Called")
}
func (Baz) Show() {
fmt.Println("Baz Showed")
}
func main() {
Foo{}.Call()
Bar{}.Call()
Baz{}.Call()
}
// Output:
// Foo Called
// Foo Showed
// Foo Called
// Foo Showed
// Baz Called
yaegi-0.10.0/_test/method6.go 0000664 0000000 0000000 00000000337 14120400617 0015677 0 ustar 00root root 0000000 0000000 package main
type Sample struct {
Name string
}
func (s Sample) foo(i int) {
println("in foo", s.Name, i)
}
var samples = []Sample{
Sample{"hello"},
}
func main() {
samples[0].foo(3)
}
// Output:
// in foo hello 3
yaegi-0.10.0/_test/method7.go 0000664 0000000 0000000 00000000340 14120400617 0015672 0 ustar 00root root 0000000 0000000 package main
type Sample struct {
Name string
}
func (s *Sample) foo(i int) {
println("in foo", s.Name, i)
}
var samples = []Sample{
Sample{"hello"},
}
func main() {
samples[0].foo(3)
}
// Output:
// in foo hello 3
yaegi-0.10.0/_test/method8.go 0000664 0000000 0000000 00000000413 14120400617 0015674 0 ustar 00root root 0000000 0000000 package main
type Sample struct {
Name string
Foo []string
}
func (s *Sample) foo(j int) {
for i, v := range s.Foo {
println(i, v)
}
}
var samples = []Sample{
Sample{"hello", []string{"world"}},
}
func main() {
samples[0].foo(3)
}
// Output:
// 0 world
yaegi-0.10.0/_test/method9.go 0000664 0000000 0000000 00000000256 14120400617 0015702 0 ustar 00root root 0000000 0000000 package main
type Coord struct {
x, y int
}
func main() {
o := Coord{3, 4}
println(o.dist())
}
func (c Coord) dist() int { return c.x*c.x + c.y*c.y }
// Output:
// 25
yaegi-0.10.0/_test/neg0.go 0000664 0000000 0000000 00000000127 14120400617 0015157 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := -1
fmt.Println(a)
}
// Output:
// -1
yaegi-0.10.0/_test/new0.go 0000664 0000000 0000000 00000000123 14120400617 0015173 0 ustar 00root root 0000000 0000000 package main
func main() {
a := new(int)
*a = 3
println(*a)
}
// Output:
// 3
yaegi-0.10.0/_test/new1.go 0000664 0000000 0000000 00000000175 14120400617 0015203 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [1]*int{}
a[0] = new(int)
*a[0] = 2
fmt.Println(*a[0])
}
// Output:
// 2
yaegi-0.10.0/_test/new2.go 0000664 0000000 0000000 00000000172 14120400617 0015201 0 ustar 00root root 0000000 0000000 package main
func f() interface{} {
return new(int)
}
func main() {
a := f()
println(*(a.(*int)))
}
// Output:
// 0
yaegi-0.10.0/_test/nil0.go 0000664 0000000 0000000 00000000256 14120400617 0015173 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f() (host, port string, err error) {
return "", "", nil
}
func main() {
h, p, err := f()
fmt.Println(h, p, err)
}
// Output:
//
yaegi-0.10.0/_test/nil1.go 0000664 0000000 0000000 00000000210 14120400617 0015162 0 ustar 00root root 0000000 0000000 package main
func main() {
var a error = nil
if a == nil || a.Error() == "nil" {
println("a is nil")
}
}
// Output:
// a is nil
yaegi-0.10.0/_test/nil2.go 0000664 0000000 0000000 00000000225 14120400617 0015171 0 ustar 00root root 0000000 0000000 package main
func test() error { return nil }
func main() {
if err := test(); nil == err {
println("err is nil")
}
}
// Output:
// err is nil
yaegi-0.10.0/_test/nil3.go 0000664 0000000 0000000 00000000453 14120400617 0015175 0 ustar 00root root 0000000 0000000 package main
type I interface {
Hello()
}
type T struct {
h I
}
func (t *T) Hello() { println("Hello") }
func main() {
t := &T{}
println(t.h != nil)
println(t.h == nil)
t.h = t
println(t.h != nil)
println(t.h == nil)
t.h.Hello()
}
// Output:
// false
// true
// true
// false
// Hello
yaegi-0.10.0/_test/not0.go 0000664 0000000 0000000 00000000206 14120400617 0015204 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 0
b := true
c := false
if b && c {
a = 1
} else {
a = -1
}
println(a)
}
// Output:
// -1
yaegi-0.10.0/_test/not1.go 0000664 0000000 0000000 00000000276 14120400617 0015214 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 0
b := true
if (!b) {
a = 1
} else {
a = -1
}
println(a)
}
// Output:
// -1
yaegi-0.10.0/_test/not2.go 0000664 0000000 0000000 00000000144 14120400617 0015207 0 ustar 00root root 0000000 0000000 package main
func main() {
var b interface{} = !(1 == 2)
println(b.(bool))
}
// Output:
// true
yaegi-0.10.0/_test/num0.go 0000664 0000000 0000000 00000000126 14120400617 0015204 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
fmt.Printf("%g\n", 1.0)
}
// Output:
// 1
yaegi-0.10.0/_test/op0.go 0000664 0000000 0000000 00000000227 14120400617 0015025 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a, b, c uint16
a = 64
b = 64
c = a * b
fmt.Printf("c: %v %T", c, c)
}
// Output:
// c: 4096 uint16
yaegi-0.10.0/_test/op1.go 0000664 0000000 0000000 00000000220 14120400617 0015017 0 ustar 00root root 0000000 0000000 package main
func main() {
var a int = 3
a += 1.3
println(a)
}
// Error:
// 5:2: invalid operation: mismatched types int and untyped float
yaegi-0.10.0/_test/op2.go 0000664 0000000 0000000 00000000670 14120400617 0015031 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := 64
a += 64
fmt.Printf("a: %v %T", a, a)
fmt.Println()
b := 64
b -= 64
fmt.Printf("b: %v %T", b, b)
fmt.Println()
c := 64
c *= 64
fmt.Printf("c: %v %T", c, c)
fmt.Println()
d := 64
d /= 64
fmt.Printf("d: %v %T", d, d)
fmt.Println()
e := 64
e %= 64
fmt.Printf("e: %v %T", e, e)
fmt.Println()
}
// Output:
// a: 128 int
// b: 0 int
// c: 4096 int
// d: 1 int
// e: 0 int
yaegi-0.10.0/_test/op3.go 0000664 0000000 0000000 00000000277 14120400617 0015035 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := -1.2
fmt.Printf("a: %v %T\n", a, a)
b := -(2 + 1i)
fmt.Printf("b: %v %T\n", b, b)
}
// Output:
// a: -1.2 float64
// b: (-2-1i) complex128
yaegi-0.10.0/_test/op4.go 0000664 0000000 0000000 00000000114 14120400617 0015024 0 ustar 00root root 0000000 0000000 package main
func main() {
i := 102
println(i % -1e2)
}
// Output:
// 2
yaegi-0.10.0/_test/op5.go 0000664 0000000 0000000 00000000166 14120400617 0015034 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
i := 100
j := i % 1e2
fmt.Printf("%T %v\n", j, j)
}
// Output:
// int 0
yaegi-0.10.0/_test/op6.go 0000664 0000000 0000000 00000000265 14120400617 0015035 0 ustar 00root root 0000000 0000000 package main
type T int
func (t T) Error() string { return "T: error" }
var invalidT T
func main() {
var err error
if err != invalidT {
println("ok")
}
}
// Output:
// ok
yaegi-0.10.0/_test/op7.go 0000664 0000000 0000000 00000000366 14120400617 0015040 0 ustar 00root root 0000000 0000000 package main
type T int
func (t T) Error() string { return "T: error" }
var invalidT T
func main() {
var err error
if err > invalidT {
println("ok")
}
}
// Error:
// _test/op7.go:11:5: invalid operation: operator > not defined on error
yaegi-0.10.0/_test/op8.go 0000664 0000000 0000000 00000000316 14120400617 0015034 0 ustar 00root root 0000000 0000000 package main
type I interface {
Get() interface{}
}
type T struct{}
func (T) Get() interface{} {
return nil
}
func main() {
var i I = T{}
var ei interface{}
println(i != ei)
}
// Output:
// true
yaegi-0.10.0/_test/op9.go 0000664 0000000 0000000 00000000265 14120400617 0015040 0 ustar 00root root 0000000 0000000 package main
func main() {
var i complex128 = 1i
var f complex128 = 0.4i
print(i > f)
}
// Error:
// _test/op9.go:7:8: invalid operation: operator > not defined on complex128
yaegi-0.10.0/_test/opfloat32.go 0000664 0000000 0000000 00000001254 14120400617 0016141 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a float32 = 64
a += 64
fmt.Printf("a: %v %T", a, a)
fmt.Println()
var b float32 = 64
b -= 64
fmt.Printf("b: %v %T", b, b)
fmt.Println()
var c float32 = 64
c *= 64
fmt.Printf("c: %v %T", c, c)
fmt.Println()
var d float32 = 64
d /= 64
fmt.Printf("d: %v %T", d, d)
fmt.Println()
// FIXME expect an error
// var e float32 = 64
// e %= 64
// fmt.Printf("e: %v %T", e, e)
// fmt.Println()
fmt.Println(a > b)
fmt.Println(a >= b)
fmt.Println(a < b)
fmt.Println(a <= b)
fmt.Println(b == d)
}
// Output:
// a: 128 float32
// b: 0 float32
// c: 4096 float32
// d: 1 float32
// true
// true
// false
// false
// false
yaegi-0.10.0/_test/opfloat64.go 0000664 0000000 0000000 00000001254 14120400617 0016146 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a float64 = 64
a += 64
fmt.Printf("a: %v %T", a, a)
fmt.Println()
var b float64 = 64
b -= 64
fmt.Printf("b: %v %T", b, b)
fmt.Println()
var c float64 = 64
c *= 64
fmt.Printf("c: %v %T", c, c)
fmt.Println()
var d float64 = 64
d /= 64
fmt.Printf("d: %v %T", d, d)
fmt.Println()
// FIXME expect an error
// var e float64 = 64
// e %= 64
// fmt.Printf("e: %v %T", e, e)
// fmt.Println()
fmt.Println(a > b)
fmt.Println(a >= b)
fmt.Println(a < b)
fmt.Println(a <= b)
fmt.Println(b == d)
}
// Output:
// a: 128 float64
// b: 0 float64
// c: 4096 float64
// d: 1 float64
// true
// true
// false
// false
// false
yaegi-0.10.0/_test/opint16.go 0000664 0000000 0000000 00000001201 14120400617 0015620 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a int16 = 64
a += 64
fmt.Printf("a: %v %T", a, a)
fmt.Println()
var b int16 = 64
b -= 64
fmt.Printf("b: %v %T", b, b)
fmt.Println()
var c int16 = 64
c *= 64
fmt.Printf("c: %v %T", c, c)
fmt.Println()
var d int16 = 64
d /= 64
fmt.Printf("d: %v %T", d, d)
fmt.Println()
var e int16 = 64
e %= 64
fmt.Printf("e: %v %T", e, e)
fmt.Println()
fmt.Println(a > b)
fmt.Println(a >= b)
fmt.Println(a < b)
fmt.Println(a <= b)
fmt.Println(b == e)
}
// Output:
// a: 128 int16
// b: 0 int16
// c: 4096 int16
// d: 1 int16
// e: 0 int16
// true
// true
// false
// false
// true
yaegi-0.10.0/_test/opint32.go 0000664 0000000 0000000 00000001201 14120400617 0015616 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a int32 = 64
a += 64
fmt.Printf("a: %v %T", a, a)
fmt.Println()
var b int32 = 64
b -= 64
fmt.Printf("b: %v %T", b, b)
fmt.Println()
var c int32 = 64
c *= 64
fmt.Printf("c: %v %T", c, c)
fmt.Println()
var d int32 = 64
d /= 64
fmt.Printf("d: %v %T", d, d)
fmt.Println()
var e int32 = 64
e %= 64
fmt.Printf("e: %v %T", e, e)
fmt.Println()
fmt.Println(a > b)
fmt.Println(a >= b)
fmt.Println(a < b)
fmt.Println(a <= b)
fmt.Println(b == e)
}
// Output:
// a: 128 int32
// b: 0 int32
// c: 4096 int32
// d: 1 int32
// e: 0 int32
// true
// true
// false
// false
// true
yaegi-0.10.0/_test/opint64.go 0000664 0000000 0000000 00000001201 14120400617 0015623 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a int64 = 64
a += 64
fmt.Printf("a: %v %T", a, a)
fmt.Println()
var b int64 = 64
b -= 64
fmt.Printf("b: %v %T", b, b)
fmt.Println()
var c int64 = 64
c *= 64
fmt.Printf("c: %v %T", c, c)
fmt.Println()
var d int64 = 64
d /= 64
fmt.Printf("d: %v %T", d, d)
fmt.Println()
var e int64 = 64
e %= 64
fmt.Printf("e: %v %T", e, e)
fmt.Println()
fmt.Println(a > b)
fmt.Println(a >= b)
fmt.Println(a < b)
fmt.Println(a <= b)
fmt.Println(b == e)
}
// Output:
// a: 128 int64
// b: 0 int64
// c: 4096 int64
// d: 1 int64
// e: 0 int64
// true
// true
// false
// false
// true
yaegi-0.10.0/_test/opint8.go 0000664 0000000 0000000 00000001152 14120400617 0015546 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a int8 = 6
a += 6
fmt.Printf("a: %v %T", a, a)
fmt.Println()
var b int8 = 6
b -= 6
fmt.Printf("b: %v %T", b, b)
fmt.Println()
var c int8 = 6
c *= 6
fmt.Printf("c: %v %T", c, c)
fmt.Println()
var d int8 = 6
d /= 6
fmt.Printf("d: %v %T", d, d)
fmt.Println()
var e int8 = 6
e %= 6
fmt.Printf("e: %v %T", e, e)
fmt.Println()
fmt.Println(a > b)
fmt.Println(a >= b)
fmt.Println(a < b)
fmt.Println(a <= b)
fmt.Println(b == e)
}
// Output:
// a: 12 int8
// b: 0 int8
// c: 36 int8
// d: 1 int8
// e: 0 int8
// true
// true
// false
// false
// true
yaegi-0.10.0/_test/opstring.go 0000664 0000000 0000000 00000001344 14120400617 0016175 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := "hhh"
a += "fff"
fmt.Printf("a: %v %T", a, a)
fmt.Println()
// b := "hhh"
// b -= "fff" // FIXME expect an error
// fmt.Printf("b: %v %T", b, b)
// fmt.Println()
//
// c := "hhh"
// c *= "fff" // FIXME expect an error
// fmt.Printf("c: %v %T", c, c)
// fmt.Println()
//
// d := "hhh"
// d /= "fff" // FIXME expect an error
// fmt.Printf("d: %v %T", d, d)
// fmt.Println()
//
// e := "hhh"
// e %= "fff" // FIXME expect an error
// fmt.Printf("e: %v %T", e, e)
// fmt.Println()
// FIXME panic
// fmt.Println(a > "ggg")
// fmt.Println(a >= "ggg")
// fmt.Println(a < "ggg")
// fmt.Println(a <= "ggg")
// fmt.Println(a == "hhhfff")
}
// Output:
// a: hhhfff string
yaegi-0.10.0/_test/opuint16.go 0000664 0000000 0000000 00000001213 14120400617 0016010 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a uint16 = 64
a += 64
fmt.Printf("a: %v %T", a, a)
fmt.Println()
var b uint16 = 64
b -= 64
fmt.Printf("b: %v %T", b, b)
fmt.Println()
var c uint16 = 64
c *= 64
fmt.Printf("c: %v %T", c, c)
fmt.Println()
var d uint16 = 64
d /= 64
fmt.Printf("d: %v %T", d, d)
fmt.Println()
var e uint16 = 64
e %= 64
fmt.Printf("e: %v %T", e, e)
fmt.Println()
fmt.Println(a > b)
fmt.Println(a >= b)
fmt.Println(a < b)
fmt.Println(a <= b)
fmt.Println(b == e)
}
// Output:
// a: 128 uint16
// b: 0 uint16
// c: 4096 uint16
// d: 1 uint16
// e: 0 uint16
// true
// true
// false
// false
// true
yaegi-0.10.0/_test/opuint32.go 0000664 0000000 0000000 00000001213 14120400617 0016006 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a uint32 = 64
a += 64
fmt.Printf("a: %v %T", a, a)
fmt.Println()
var b uint32 = 64
b -= 64
fmt.Printf("b: %v %T", b, b)
fmt.Println()
var c uint32 = 64
c *= 64
fmt.Printf("c: %v %T", c, c)
fmt.Println()
var d uint32 = 64
d /= 64
fmt.Printf("d: %v %T", d, d)
fmt.Println()
var e uint32 = 64
e %= 64
fmt.Printf("e: %v %T", e, e)
fmt.Println()
fmt.Println(a > b)
fmt.Println(a >= b)
fmt.Println(a < b)
fmt.Println(a <= b)
fmt.Println(b == e)
}
// Output:
// a: 128 uint32
// b: 0 uint32
// c: 4096 uint32
// d: 1 uint32
// e: 0 uint32
// true
// true
// false
// false
// true
yaegi-0.10.0/_test/opuint64.go 0000664 0000000 0000000 00000001213 14120400617 0016013 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a uint64 = 64
a += 64
fmt.Printf("a: %v %T", a, a)
fmt.Println()
var b uint64 = 64
b -= 64
fmt.Printf("b: %v %T", b, b)
fmt.Println()
var c uint64 = 64
c *= 64
fmt.Printf("c: %v %T", c, c)
fmt.Println()
var d uint64 = 64
d /= 64
fmt.Printf("d: %v %T", d, d)
fmt.Println()
var e uint64 = 64
e %= 64
fmt.Printf("e: %v %T", e, e)
fmt.Println()
fmt.Println(a > b)
fmt.Println(a >= b)
fmt.Println(a < b)
fmt.Println(a <= b)
fmt.Println(b == e)
}
// Output:
// a: 128 uint64
// b: 0 uint64
// c: 4096 uint64
// d: 1 uint64
// e: 0 uint64
// true
// true
// false
// false
// true
yaegi-0.10.0/_test/opuint8.go 0000664 0000000 0000000 00000001164 14120400617 0015736 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a uint8 = 6
a += 6
fmt.Printf("a: %v %T", a, a)
fmt.Println()
var b uint8 = 6
b -= 6
fmt.Printf("b: %v %T", b, b)
fmt.Println()
var c uint8 = 6
c *= 6
fmt.Printf("c: %v %T", c, c)
fmt.Println()
var d uint8 = 6
d /= 6
fmt.Printf("d: %v %T", d, d)
fmt.Println()
var e uint8 = 6
e %= 6
fmt.Printf("e: %v %T", e, e)
fmt.Println()
fmt.Println(a > b)
fmt.Println(a >= b)
fmt.Println(a < b)
fmt.Println(a <= b)
fmt.Println(b == e)
}
// Output:
// a: 12 uint8
// b: 0 uint8
// c: 36 uint8
// d: 1 uint8
// e: 0 uint8
// true
// true
// false
// false
// true
yaegi-0.10.0/_test/or0.go 0000664 0000000 0000000 00000000120 14120400617 0015017 0 ustar 00root root 0000000 0000000 package main
func main() {
c := false
println(c || !c)
}
// Output:
// true
yaegi-0.10.0/_test/or1.go 0000664 0000000 0000000 00000000120 14120400617 0015020 0 ustar 00root root 0000000 0000000 package main
func main() {
c := false
println(!c || c)
}
// Output:
// true
yaegi-0.10.0/_test/or2.go 0000664 0000000 0000000 00000000125 14120400617 0015026 0 ustar 00root root 0000000 0000000 package main
var a = false || true
func main() {
println(a)
}
// Output:
// true
yaegi-0.10.0/_test/p1/ 0000775 0000000 0000000 00000000000 14120400617 0014317 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/p1/s1.go 0000664 0000000 0000000 00000000071 14120400617 0015167 0 ustar 00root root 0000000 0000000 package p1
import "crypto/rand"
var Prime = rand.Prime
yaegi-0.10.0/_test/p1/s2.go 0000664 0000000 0000000 00000000127 14120400617 0015172 0 ustar 00root root 0000000 0000000 package p1
import "math/rand"
var Uint32 = rand.Uint32
func init() { rand.Seed(1) }
yaegi-0.10.0/_test/pkgname0.go 0000664 0000000 0000000 00000000446 14120400617 0016034 0 ustar 00root root 0000000 0000000 package main
import (
"guthib.com/bar" // pkg name is actually quux
baz "guthib.com/baz" // pkg name is also quux, force it to baz.
)
func main() {
println("Hello", quux.Quux())
println("Hello", baz.Quux())
}
// GOPATH:testdata/redeclaration-global7
// Output:
// Hello bar
// Hello baz
yaegi-0.10.0/_test/pkgname1.go 0000664 0000000 0000000 00000000375 14120400617 0016036 0 ustar 00root root 0000000 0000000 package main
import (
"guthib.com/bar" // pkg name is actually quux
)
func main() {
println("Hello", bar.Quux()) // bar should not be a known symbol.
}
// GOPATH:testdata/redeclaration-global7
// Error:
// ../_test/pkgname1.go:8:19: undefined: bar
yaegi-0.10.0/_test/pkgname2.go 0000664 0000000 0000000 00000000273 14120400617 0016034 0 ustar 00root root 0000000 0000000 package main
import (
"guthib.com/toto" // pkg name is actually titi
)
func main() {
println("Hello", titi.Quux())
}
// GOPATH:testdata/redeclaration-global7
// Output:
// Hello bar
yaegi-0.10.0/_test/primes.go 0000664 0000000 0000000 00000000451 14120400617 0015625 0 ustar 00root root 0000000 0000000 package main
func Primes(n int) int {
var xs []int
for i := 2; len(xs) < n; i++ {
ok := true
for _, x := range xs {
if i%x == 0 {
ok = false
break
}
}
if !ok {
continue
}
xs = append(xs, i)
}
return xs[n-1]
}
func main() {
println(Primes(3))
}
// Output:
// 5
yaegi-0.10.0/_test/print0.go 0000664 0000000 0000000 00000000103 14120400617 0015534 0 ustar 00root root 0000000 0000000 package main
func main() {
print("hello")
}
// Output:
// hello
yaegi-0.10.0/_test/ptr0.go 0000664 0000000 0000000 00000000160 14120400617 0015210 0 ustar 00root root 0000000 0000000 package main
type myint int
func main() {
var a myint = 2
var b *myint = &a
println(*b)
}
// Output:
// 2
yaegi-0.10.0/_test/ptr1.go 0000664 0000000 0000000 00000000124 14120400617 0015211 0 ustar 00root root 0000000 0000000 package main
func main() {
var a int = 2
b := &a
println(*b)
}
// Output:
// 2
yaegi-0.10.0/_test/ptr2.go 0000664 0000000 0000000 00000000162 14120400617 0015214 0 ustar 00root root 0000000 0000000 package main
func f(i *int) {
*i = *i + 3
}
func main() {
var a int = 2
f(&a)
println(a)
}
// Output:
// 5
yaegi-0.10.0/_test/ptr3.go 0000664 0000000 0000000 00000000153 14120400617 0015215 0 ustar 00root root 0000000 0000000 package main
func f(i *int) {
*i++
}
func main() {
var a int = 2
f(&a)
println(a)
}
// Output:
// 3
yaegi-0.10.0/_test/ptr4.go 0000664 0000000 0000000 00000000233 14120400617 0015215 0 ustar 00root root 0000000 0000000 package main
type Foo struct {
val int
}
func f(p *Foo) {
p.val = p.val + 2
}
func main() {
var a = Foo{3}
f(&a)
println(a.val)
}
// Output:
// 5
yaegi-0.10.0/_test/ptr5.go 0000664 0000000 0000000 00000000156 14120400617 0015222 0 ustar 00root root 0000000 0000000 package main
type Foo struct {
val int
}
func main() {
var a = &Foo{3}
println(a.val)
}
// Output:
// 3
yaegi-0.10.0/_test/ptr5a.go 0000664 0000000 0000000 00000000166 14120400617 0015364 0 ustar 00root root 0000000 0000000 package main
type Foo struct {
val int
}
func main() {
var a = Foo{3}
b := &a
println(b.val)
}
// Output:
// 3
yaegi-0.10.0/_test/ptr6.go 0000664 0000000 0000000 00000000166 14120400617 0015224 0 ustar 00root root 0000000 0000000 package main
type Foo struct {
val int
}
func main() {
var a = Foo{3}
b := &a
println(b.val)
}
// Output:
// 3
yaegi-0.10.0/_test/ptr7.go 0000664 0000000 0000000 00000000520 14120400617 0015217 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net"
"strings"
)
type ipNetValue net.IPNet
func (ipnet *ipNetValue) Set(value string) error {
_, n, err := net.ParseCIDR(strings.TrimSpace(value))
if err != nil {
return err
}
*ipnet = ipNetValue(*n)
return nil
}
func main() {
v := ipNetValue{}
fmt.Println(v)
}
// Output:
// { }
yaegi-0.10.0/_test/ptr8.go 0000664 0000000 0000000 00000000170 14120400617 0015221 0 ustar 00root root 0000000 0000000 package main
var a = func() *bool { b := true; return &b }()
func main() {
println(*a && true)
}
// Output:
// true
yaegi-0.10.0/_test/ptr_array0.go 0000664 0000000 0000000 00000000200 14120400617 0016401 0 ustar 00root root 0000000 0000000 package main
type T [2]int
func F0(t *T) int { return t[0] }
func main() {
t := &T{1, 2}
println(F0(t))
}
// Output:
// 1
yaegi-0.10.0/_test/ptr_array1.go 0000664 0000000 0000000 00000000244 14120400617 0016412 0 ustar 00root root 0000000 0000000 package main
type T [3]int
func F0(t *T) {
for i, v := range t {
println(i, v)
}
}
func main() {
t := &T{1, 2, 3}
F0(t)
}
// Output:
// 0 1
// 1 2
// 2 3
yaegi-0.10.0/_test/ptr_array2.go 0000664 0000000 0000000 00000000217 14120400617 0016413 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T [2]int
func F1(t *T) { t[0] = 1 }
func main() {
t := &T{}
F1(t)
fmt.Println(t)
}
// Output:
// &[1 0]
yaegi-0.10.0/_test/ptr_array3.go 0000664 0000000 0000000 00000000157 14120400617 0016417 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := &[...]int{1, 2, 3}
fmt.Println(a[:])
}
// Output:
// [1 2 3]
yaegi-0.10.0/_test/range0.go 0000664 0000000 0000000 00000000230 14120400617 0015475 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
v := []int{1, 2, 3}
for i := range v {
v = append(v, i)
}
fmt.Println(v)
}
// Output:
// [1 2 3 0 1 2]
yaegi-0.10.0/_test/range1.go 0000664 0000000 0000000 00000000220 14120400617 0015475 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [...]int{2, 1, 0}
for _, v := range a {
a[v] = v
}
fmt.Println(a)
}
// Output:
// [0 1 2]
yaegi-0.10.0/_test/range2.go 0000664 0000000 0000000 00000000221 14120400617 0015477 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [...]int{2, 1, 0}
for _, v := range &a {
a[v] = v
}
fmt.Println(a)
}
// Output:
// [2 1 2]
yaegi-0.10.0/_test/range3.go 0000664 0000000 0000000 00000000246 14120400617 0015507 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
m := map[int]bool{1: true, 3: true, 5: true}
for k := range m {
m[k*2] = true
}
fmt.Println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/range4.go 0000664 0000000 0000000 00000000251 14120400617 0015504 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
m := map[int]bool{1: true, 3: true, 5: true}
for _, v := range m {
fmt.Println(v)
}
}
// Output:
// true
// true
// true
yaegi-0.10.0/_test/range5.go 0000664 0000000 0000000 00000000236 14120400617 0015510 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
m := map[int]bool{1: true, 3: true, 5: true}
var n int
for range m {
n++
}
fmt.Println(n)
}
// Output:
// 3
yaegi-0.10.0/_test/range6.go 0000664 0000000 0000000 00000000325 14120400617 0015510 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math"
)
func main() {
m := map[float64]bool{math.NaN(): true, math.NaN(): true, math.NaN(): true}
for _, v := range m {
fmt.Println(v)
}
}
// Output:
// true
// true
// true
yaegi-0.10.0/_test/range7.go 0000664 0000000 0000000 00000000345 14120400617 0015513 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
func someChan() <-chan struct{} {
c := make(chan struct{}, 1)
c <- struct{}{}
return c
}
func main() {
for _ = range someChan() {
fmt.Println("success")
return
}
}
// Output:
// success yaegi-0.10.0/_test/range8.go 0000664 0000000 0000000 00000000242 14120400617 0015510 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func main() {
for _ = range time.Tick(time.Millisecond) {
fmt.Println("success")
return
}
}
// Output:
// success
yaegi-0.10.0/_test/range9.go 0000664 0000000 0000000 00000000300 14120400617 0015504 0 ustar 00root root 0000000 0000000 package main
func main() {
var c chan<- struct{} = make(chan struct{})
for _ = range c {
}
}
// Error:
// _test/range9.go:6:16: invalid operation: range c receive from send-only channel
yaegi-0.10.0/_test/real0.go 0000664 0000000 0000000 00000000253 14120400617 0015331 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f(c complex128) interface{} { return real(c) }
func main() {
c := complex(3, 2)
a := f(c)
fmt.Println(a.(float64))
}
// Output:
// 3
yaegi-0.10.0/_test/recover0.go 0000664 0000000 0000000 00000000303 14120400617 0016047 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
println("hello")
defer func() {
r := recover()
fmt.Println("recover:", r)
}()
println("world")
}
// Output:
// hello
// world
// recover:
yaegi-0.10.0/_test/recover1.go 0000664 0000000 0000000 00000000324 14120400617 0016053 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
println("hello")
defer func() {
r := recover()
fmt.Println("recover:", r)
}()
panic("test panic")
println("world")
}
// Output:
// hello
// recover: test panic
yaegi-0.10.0/_test/recover2.go 0000664 0000000 0000000 00000000232 14120400617 0016052 0 ustar 00root root 0000000 0000000 package main
func main() {
println("hello")
var r interface{} = 1
r = recover()
if r == nil {
println("world")
}
}
// Output:
// hello
// world
yaegi-0.10.0/_test/recover3.go 0000664 0000000 0000000 00000000361 14120400617 0016056 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
println("hello")
var r interface{} = 1
r = recover()
fmt.Printf("%v\n", r)
if r == nil {
println("world")
}
if r != nil {
println("exception")
}
}
// Output:
// hello
//
// world
yaegi-0.10.0/_test/recover4.go 0000664 0000000 0000000 00000000373 14120400617 0016062 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func div(a, b int) (result int) {
defer func() {
r := recover()
fmt.Printf("r = %#v\n", r)
if r != nil {
result = 0
}
}()
return a / b
}
func main() {
println(div(30, 2))
}
// Output:
// r =
// 15
yaegi-0.10.0/_test/recurse0.go 0000664 0000000 0000000 00000000777 14120400617 0016071 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T struct {
a []T
b []*T
c map[string]T
d map[string]*T
e chan T
f chan *T
h *T
i func(T) T
j func(*T) *T
U
}
type U struct {
k []T
l []*T
m map[string]T
n map[string]*T
o chan T
p chan *T
q *T
r func(T) T
s func(*T) *T
}
func main() {
t := T{}
u := U{}
fmt.Println(t)
fmt.Println(u)
}
// Output:
// {[] [] map[] map[] {[] [] map[] map[] }}
// {[] [] map[] map[] }
yaegi-0.10.0/_test/redeclaration-global0.go 0000664 0000000 0000000 00000000361 14120400617 0020460 0 ustar 00root root 0000000 0000000 package main
type time int
var time string
func main() {
time = "hello"
println(time)
}
// Error:
// ../_test/redeclaration-global0.go:5:5: time redeclared in this block
// previous declaration at ../_test/redeclaration-global0.go:3:6
yaegi-0.10.0/_test/redeclaration-global1.go 0000664 0000000 0000000 00000000210 14120400617 0020452 0 ustar 00root root 0000000 0000000 package main
var time int
type time string
func main() {
var t time = "hello"
println(t)
}
// TODO: expected redeclaration error.
yaegi-0.10.0/_test/redeclaration-global2.go 0000664 0000000 0000000 00000000314 14120400617 0020460 0 ustar 00root root 0000000 0000000 package main
import (
"time"
"time"
)
func main() {
var t time.Time
println(t.String())
}
// Error:
// ../_test/redeclaration-global2.go:5:2: time/redeclaration-global2.go redeclared in this block
yaegi-0.10.0/_test/redeclaration-global3.go 0000664 0000000 0000000 00000000262 14120400617 0020463 0 ustar 00root root 0000000 0000000 package main
import (
"time"
)
var time string
func main() {
time = "hello"
println(t)
}
// Error:
// ../_test/redeclaration-global3.go:7:5: time redeclared in this block
yaegi-0.10.0/_test/redeclaration-global4.go 0000664 0000000 0000000 00000000271 14120400617 0020464 0 ustar 00root root 0000000 0000000 package main
import (
"time"
)
type time string
func main() {
var t time = "hello"
println(t)
}
// Error:
// ../_test/redeclaration-global4.go:7:6: time redeclared in this block
yaegi-0.10.0/_test/redeclaration-global5.go 0000664 0000000 0000000 00000000401 14120400617 0020460 0 ustar 00root root 0000000 0000000 package main
var time int
func time() string {
return "hello"
}
func main() {
t := time()
println(t)
}
// Error:
// ../_test/redeclaration-global5.go:5:6: time redeclared in this block
// previous declaration at ../_test/redeclaration-global5.go:3:5
yaegi-0.10.0/_test/redeclaration-global6.go 0000664 0000000 0000000 00000000306 14120400617 0020465 0 ustar 00root root 0000000 0000000 package main
import (
"time"
)
func time() string {
return "hello"
}
func main() {
t := time()
println(t)
}
// Error:
// ../_test/redeclaration-global6.go:7:1: time redeclared in this block
yaegi-0.10.0/_test/redeclaration-global7.go 0000664 0000000 0000000 00000000503 14120400617 0020465 0 ustar 00root root 0000000 0000000 package main
import (
"guthib.com/bar" // pkg name is actually quux
"guthib.com/baz" // pkg name is also quux
)
func main() {
println("Hello", quux.Quux())
}
// GOPATH:testdata/redeclaration-global7
// Error:
// ../_test/redeclaration-global7.go:5:2: quux/redeclaration-global7.go redeclared as imported package name
yaegi-0.10.0/_test/redeclaration0.go 0000664 0000000 0000000 00000000354 14120400617 0017224 0 ustar 00root root 0000000 0000000 package main
func main() {
type foo struct {
yolo string
}
var foo int
foo = 2
println(foo)
}
// Error:
// ../_test/redeclaration0.go:8:6: foo redeclared in this block
// previous declaration at ../_test/redeclaration0.go:4:7
yaegi-0.10.0/_test/redeclaration1.go 0000664 0000000 0000000 00000000236 14120400617 0017224 0 ustar 00root root 0000000 0000000 package main
func main() {
var foo string
var foo int
foo = 2
println(foo)
}
// Error:
// ../_test/redeclaration1.go:6:6: foo redeclared in this block
yaegi-0.10.0/_test/redeclaration2.go 0000664 0000000 0000000 00000000353 14120400617 0017225 0 ustar 00root root 0000000 0000000 package main
func main() {
var foo struct {
yolo string
}
var foo int
foo = 2
println(foo)
}
// Error:
// ../_test/redeclaration2.go:8:6: foo redeclared in this block
// previous declaration at ../_test/redeclaration2.go:4:6
yaegi-0.10.0/_test/redeclaration3.go 0000664 0000000 0000000 00000000256 14120400617 0017230 0 ustar 00root root 0000000 0000000 package main
func main() {
var foo int
foo = 2
type foo struct{}
var bar foo
println(bar)
}
// Error:
// ../_test/redeclaration3.go:7:7: foo redeclared in this block
yaegi-0.10.0/_test/redeclaration4.go 0000664 0000000 0000000 00000000272 14120400617 0017227 0 ustar 00root root 0000000 0000000 package main
func main() {
var foo struct{
yolo string
}
type foo struct{}
var bar foo
println(bar)
}
// Error:
// ../_test/redeclaration4.go:8:7: foo redeclared in this block
yaegi-0.10.0/_test/redeclaration5.go 0000664 0000000 0000000 00000000273 14120400617 0017231 0 ustar 00root root 0000000 0000000 package main
func main() {
type foo struct{
yolo string
}
type foo struct{}
var bar foo
println(bar)
}
// Error:
// ../_test/redeclaration5.go:8:7: foo redeclared in this block
yaegi-0.10.0/_test/restricted0.go 0000664 0000000 0000000 00000000351 14120400617 0016555 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"log"
)
func main() {
defer func() {
r := recover()
fmt.Println("recover:", r)
}()
log.Fatal("log.Fatal does not exit")
println("not printed")
}
// Output:
// recover: log.Fatal does not exit
yaegi-0.10.0/_test/restricted1.go 0000664 0000000 0000000 00000000301 14120400617 0016551 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"os"
)
func main() {
defer func() {
r := recover()
fmt.Println("recover:", r)
}()
os.Exit(1)
println("not printed")
}
// Output:
// recover: os.Exit(1)
yaegi-0.10.0/_test/restricted2.go 0000664 0000000 0000000 00000000223 14120400617 0016555 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"os"
)
func main() {
p, err := os.FindProcess(os.Getpid())
fmt.Println(p, err)
}
// Output:
// restricted
yaegi-0.10.0/_test/restricted3.go 0000664 0000000 0000000 00000000502 14120400617 0016556 0 ustar 00root root 0000000 0000000 package main
import (
"bytes"
"fmt"
"log"
)
var (
buf bytes.Buffer
logger = log.New(&buf, "logger: ", log.Lshortfile)
)
func main() {
defer func() {
r := recover()
fmt.Println("recover:", r, buf.String())
}()
logger.Fatal("test log")
}
// Output:
// recover: test log logger: restricted.go:39: test log
yaegi-0.10.0/_test/ret1.go 0000664 0000000 0000000 00000000152 14120400617 0015177 0 ustar 00root root 0000000 0000000 package main
func f(i int) (o int) { o = i + 1; return }
func main() { println(f(4)) }
// Output:
// 5
yaegi-0.10.0/_test/ret2.go 0000664 0000000 0000000 00000000164 14120400617 0015203 0 ustar 00root root 0000000 0000000 package main
func r2() (int, int) { return 1, 2 }
func main() {
a, b := r2()
println(a, b)
}
// Output:
// 1 2
yaegi-0.10.0/_test/ret3.go 0000664 0000000 0000000 00000000170 14120400617 0015201 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func r2() (int, int) { return 1, 2 }
func main() {
fmt.Println(r2())
}
// Output:
// 1 2
yaegi-0.10.0/_test/ret4.go 0000664 0000000 0000000 00000000140 14120400617 0015177 0 ustar 00root root 0000000 0000000 package main
func r() int { return 1 }
func main() {
a := r()
println(a)
}
// Output:
// 1
yaegi-0.10.0/_test/ret5.go 0000664 0000000 0000000 00000000172 14120400617 0015205 0 ustar 00root root 0000000 0000000 package main
func r2() (int, int) { return 1, 2 }
var a, b int = r2()
func main() { println(a, b) }
// Output:
// 1 2
yaegi-0.10.0/_test/ret6.go 0000664 0000000 0000000 00000000220 14120400617 0015200 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type Foo struct{}
func foo() *Foo { return nil }
func main() {
f := foo()
fmt.Println(f)
}
// Output:
//
yaegi-0.10.0/_test/ret7.go 0000664 0000000 0000000 00000000135 14120400617 0015206 0 ustar 00root root 0000000 0000000 package main
func one() uint {
return 1
}
func main() {
println(one())
}
// Output:
// 1
yaegi-0.10.0/_test/ret8.go 0000664 0000000 0000000 00000000666 14120400617 0015220 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type CustomError string
func (s CustomError) Error() string {
return string(s)
}
func NewCustomError(errorText string) CustomError {
return CustomError(errorText)
}
func fail() (err error) {
return NewCustomError("Everything is going wrong!")
}
func main() {
fmt.Println(fail())
var myError error
myError = NewCustomError("ok")
fmt.Println(myError)
}
// Output:
// Everything is going wrong!
// ok
yaegi-0.10.0/_test/run0.go 0000664 0000000 0000000 00000000166 14120400617 0015215 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f() (int, int) { return 2, 3 }
func main() {
fmt.Println(f())
}
// Output:
// 2 3
yaegi-0.10.0/_test/run1.go 0000664 0000000 0000000 00000000214 14120400617 0015210 0 ustar 00root root 0000000 0000000 package main
func f() (int, int) { return 2, 3 }
func g(i, j int) int { return i + j }
func main() {
println(g(f()))
}
// Output:
// 5
yaegi-0.10.0/_test/run10.go 0000664 0000000 0000000 00000000122 14120400617 0015266 0 ustar 00root root 0000000 0000000 package main
func main() {
func() { println("hello") }()
}
// Output:
// hello
yaegi-0.10.0/_test/run11.go 0000664 0000000 0000000 00000000166 14120400617 0015277 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
fmt.Println(f())
}
func f() (int, int) { return 2, 3 }
// Output:
// 2 3
yaegi-0.10.0/_test/run12.go 0000664 0000000 0000000 00000000201 14120400617 0015266 0 ustar 00root root 0000000 0000000 package main
func f(a int) (int, int) {
return a + 1, a + 2
}
func main() {
a, b := f(3)
println(a, b)
}
// Output:
// 4 5
yaegi-0.10.0/_test/run13.go 0000664 0000000 0000000 00000000201 14120400617 0015267 0 ustar 00root root 0000000 0000000 package main
func main() {
a, b := f(3)
println(a, b)
}
func f(a int) (int, int) {
return a + 1, a + 2
}
// Output:
// 4 5
yaegi-0.10.0/_test/run4.go 0000664 0000000 0000000 00000000231 14120400617 0015212 0 ustar 00root root 0000000 0000000 package main
type fn func(int)
func f1(i int) { println("f1", i) }
func test(f fn, v int) { f(v) }
func main() { test(f1, 21) }
// Output:
// f1 21
yaegi-0.10.0/_test/run5.go 0000664 0000000 0000000 00000000235 14120400617 0015217 0 ustar 00root root 0000000 0000000 package main
type fn func(int)
func test(f fn, v int) { f(v) }
func main() {
f1 := func(i int) { println("f1", i) }
test(f1, 21)
}
// Output:
// f1 21
yaegi-0.10.0/_test/run6.go 0000664 0000000 0000000 00000000223 14120400617 0015215 0 ustar 00root root 0000000 0000000 package main
type fn func(int)
func test(f fn, v int) { f(v) }
func main() {
test(func(i int) { println("f1", i) }, 21)
}
// Output:
// f1 21
yaegi-0.10.0/_test/run7.go 0000664 0000000 0000000 00000000240 14120400617 0015215 0 ustar 00root root 0000000 0000000 package main
type fn func(int)
func test(f fn, v int) { f(v) }
func main() {
a := 3
test(func(i int) { println("f1", i, a) }, 21)
}
// Output:
// f1 21 3
yaegi-0.10.0/_test/run8.go 0000664 0000000 0000000 00000000156 14120400617 0015224 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 3
f := func(i int) { println("f1", i, a) }
f(21)
}
// Output:
// f1 21 3
yaegi-0.10.0/_test/run9.go 0000664 0000000 0000000 00000000227 14120400617 0015224 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 3
f := func(i int) int { println("f1", i, a); return i + 1 }
b := f(21)
println(b)
}
// Output:
// f1 21 3
// 22
yaegi-0.10.0/_test/rune0.go 0000664 0000000 0000000 00000001142 14120400617 0015355 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := 'r'
a += 'g'
fmt.Printf("a: %v %T", a, a)
fmt.Println()
b := 'r'
b -= 'g'
fmt.Printf("b: %v %T", b, b)
fmt.Println()
c := 'r'
c *= 'g'
fmt.Printf("c: %v %T", c, c)
fmt.Println()
d := 'r'
d /= 'g'
fmt.Printf("d: %v %T", d, d)
fmt.Println()
e := 'r'
e %= 'g'
fmt.Printf("e: %v %T", e, e)
fmt.Println()
fmt.Println(a > b)
fmt.Println(a >= b)
fmt.Println(a < b)
fmt.Println(a <= b)
fmt.Println(b == d)
}
// Output:
// a: 217 int32
// b: 11 int32
// c: 11742 int32
// d: 1 int32
// e: 11 int32
// true
// true
// false
// false
// false
yaegi-0.10.0/_test/rune1.go 0000664 0000000 0000000 00000000164 14120400617 0015361 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
t := make([]byte, 2)
t[0] = '$'
fmt.Println(t)
}
// Output:
// [36 0]
yaegi-0.10.0/_test/rune2.go 0000664 0000000 0000000 00000000334 14120400617 0015361 0 ustar 00root root 0000000 0000000 package main
import "fmt"
const majorVersion = '2'
type hashed struct {
major byte
}
func main() {
fmt.Println(majorVersion)
p := new(hashed)
p.major = majorVersion
fmt.Println(p)
}
// Output:
// 50
// &{50}
yaegi-0.10.0/_test/sample.plugin 0000664 0000000 0000000 00000000460 14120400617 0016500 0 ustar 00root root 0000000 0000000 package sample
import (
"fmt"
"net/http"
)
type Sample struct{}
func (s *Sample) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
r.Header.Set("X-sample-test", "Hello")
if next != nil {
next(w, r)
}
}
func Test() {
fmt.Println("Hello from toto.Test()")
}
yaegi-0.10.0/_test/scope0.go 0000664 0000000 0000000 00000000112 14120400617 0015511 0 ustar 00root root 0000000 0000000 package main
var a int = 1
func main() {
println(a)
}
// Output:
// 1
yaegi-0.10.0/_test/scope1.go 0000664 0000000 0000000 00000000164 14120400617 0015521 0 ustar 00root root 0000000 0000000 package main
func f(a int) int {
return 2*a + 1
}
var b int = f(3)
func main() {
println(b)
}
// Output:
// 7
yaegi-0.10.0/_test/scope2.go 0000664 0000000 0000000 00000000206 14120400617 0015517 0 ustar 00root root 0000000 0000000 package main
var a int = 1
func f() { println(a) }
func main() {
println(a)
a := 2
println(a)
f()
}
// Output:
// 1
// 2
// 1
yaegi-0.10.0/_test/scope3.go 0000664 0000000 0000000 00000000154 14120400617 0015522 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 1
if a := 2; a > 0 {
println(a)
}
println(a)
}
// Output:
// 2
// 1
yaegi-0.10.0/_test/scope4.go 0000664 0000000 0000000 00000000215 14120400617 0015521 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 1
if a := 2; a > 0 {
println(a)
}
{
a := 3
println(a)
}
println(a)
}
// Output:
// 2
// 3
// 1
yaegi-0.10.0/_test/scope5.go 0000664 0000000 0000000 00000000205 14120400617 0015521 0 ustar 00root root 0000000 0000000 package main
var a int = 1
func f() { println(a) }
func main() {
println(a)
a = 2
println(a)
f()
}
// Output:
// 1
// 2
// 2
yaegi-0.10.0/_test/scope6.go 0000664 0000000 0000000 00000000243 14120400617 0015524 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var a = [3]int{1, 2, 3}
func f() { fmt.Println(a) }
func main() {
fmt.Println(a)
a[1] = 5
f()
}
// Output:
// [1 2 3]
// [1 5 3]
yaegi-0.10.0/_test/scope7.go 0000664 0000000 0000000 00000000247 14120400617 0015531 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var a = []int{1, 2, 3}
func f() { fmt.Println(a) }
func main() {
fmt.Println(a)
a = []int{6, 7}
f()
}
// Output:
// [1 2 3]
// [6 7]
yaegi-0.10.0/_test/secure.gi 0000664 0000000 0000000 00000002076 14120400617 0015613 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"github.com/unrolled/secure" // or "gopkg.in/unrolled/secure.v1"
)
var myHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello world"))
})
func main() {
secureMiddleware := secure.New(secure.Options{
AllowedHosts: []string{"example.com", "ssl.example.com"},
HostsProxyHeaders: []string{"X-Forwarded-Host"},
SSLRedirect: true,
SSLHost: "ssl.example.com",
SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"},
STSSeconds: 315360000,
STSIncludeSubdomains: true,
STSPreload: true,
FrameDeny: true,
ContentTypeNosniff: true,
BrowserXssFilter: true,
ContentSecurityPolicy: "script-src $NONCE",
PublicKey: `pin-sha256="base64+primary=="; pin-sha256="base64+backup=="; max-age=5184000; includeSubdomains; report-uri="https://www.example.com/hpkp-report"`,
IsDevelopment: false,
})
app := secureMiddleware.Handler(myHandler)
http.ListenAndServe("127.0.0.1:3000", app)
}
yaegi-0.10.0/_test/select.go 0000664 0000000 0000000 00000000720 14120400617 0015604 0 ustar 00root root 0000000 0000000 package main
import "time"
import "fmt"
func main() {
c1 := make(chan string)
c2 := make(chan string)
go func() {
time.Sleep(1e9)
c1 <- "one"
}()
go func() {
time.Sleep(2e9)
c2 <- "two"
}()
for i := 0; i < 2; i++ {
fmt.Println("start for")
select {
case msg1 := <-c1:
fmt.Println("received", msg1)
fmt.Println("finish 1")
case msg2 := <-c2:
fmt.Println("received #2", msg2)
}
fmt.Println("end for")
}
fmt.Println("Bye")
}
yaegi-0.10.0/_test/select0.go 0000664 0000000 0000000 00000000257 14120400617 0015671 0 ustar 00root root 0000000 0000000 package main
import "time"
func forever() {
select {} // block forever
println("end")
}
func main() {
go forever()
time.Sleep(1e4)
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/select1.go 0000664 0000000 0000000 00000001116 14120400617 0015665 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func main() {
c1 := make(chan string)
c2 := make(chan string)
go func() {
time.Sleep(1e7)
c1 <- "one"
}()
go func() {
time.Sleep(2e7)
c2 <- "two"
}()
for i := 0; i < 2; i++ {
fmt.Println("start for")
select {
case msg1 := <-c1:
fmt.Println("received", msg1)
fmt.Println("finish 1")
case msg2, ok := <-c2:
fmt.Println("received #2", msg2, ok)
}
fmt.Println("end for")
}
fmt.Println("Bye")
}
// Output:
// start for
// received one
// finish 1
// end for
// start for
// received #2 two true
// end for
// Bye
yaegi-0.10.0/_test/select10.go 0000664 0000000 0000000 00000000223 14120400617 0015743 0 ustar 00root root 0000000 0000000 package main
func main() {
c := make(chan string)
select {
case <-c:
println("unexpected")
default:
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/select11.go 0000664 0000000 0000000 00000000305 14120400617 0015745 0 ustar 00root root 0000000 0000000 package main
func main() {
c := make(chan string)
select {
case <-c:
println("unexpected")
default:
println("nothing received")
}
println("bye")
}
// Output:
// nothing received
// bye
yaegi-0.10.0/_test/select12.go 0000664 0000000 0000000 00000000414 14120400617 0015747 0 ustar 00root root 0000000 0000000 package main
type S struct {
q chan struct{}
}
func (s *S) Send() {
select {
case s.q <- struct{}{}:
println("sent")
default:
println("unexpected")
}
}
func main() {
s := &S{q: make(chan struct{}, 1)}
s.Send()
println("bye")
}
// Output:
// sent
// bye
yaegi-0.10.0/_test/select13.go 0000664 0000000 0000000 00000000317 14120400617 0015752 0 ustar 00root root 0000000 0000000 package main
func main() {
var c interface{} = int64(1)
q := make(chan struct{})
select {
case q <- struct{}{}:
println("unexpected")
default:
_ = c.(int64)
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/select14.go 0000664 0000000 0000000 00000001102 14120400617 0015744 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
const (
period = 100 * time.Millisecond
precision = 7 * time.Millisecond
)
func main() {
counter := 0
p := time.Now()
ticker := time.NewTicker(period)
ch := make(chan int)
go func() {
for i := 0; i < 3; i++ {
select {
case t := <-ticker.C:
counter = counter + 1
ch <- counter
if d := t.Sub(p) - period; d < -precision || d > precision {
fmt.Println("wrong delay", d)
}
p = t
}
}
ch <- 0
}()
for c := range ch {
if c == 0 {
break
}
println(c)
}
}
// Output:
// 1
// 2
// 3
yaegi-0.10.0/_test/select15.go 0000664 0000000 0000000 00000000435 14120400617 0015755 0 ustar 00root root 0000000 0000000 package main
type T struct {
c1 chan string
c2 chan string
}
func main() {
t := &T{}
t.c2 = make(chan string)
go func(c chan string) { c <- "done" }(t.c2)
select {
case msg := <-t.c1:
println("received from c1:", msg)
case <-t.c2:
}
println("Bye")
}
// Output:
// Bye
yaegi-0.10.0/_test/select2.go 0000664 0000000 0000000 00000000730 14120400617 0015667 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
func main() {
c1 := make(chan string)
c2 := make(chan string)
a := 0
go func() {
toSend := "hello"
select {
case c2 <- toSend:
a++
}
c1 <- "done"
}()
for i := 0; i < 2; i++ {
select {
case msg1 := <-c1:
fmt.Println("received from c1:", msg1)
case msg2 := <-c2:
fmt.Println("received from c2:", msg2)
}
}
fmt.Println("Bye", a)
}
// Output:
// received from c2: hello
// received from c1: done
// Bye 1
yaegi-0.10.0/_test/select3.go 0000664 0000000 0000000 00000000170 14120400617 0015666 0 ustar 00root root 0000000 0000000 package main
func main() {
select {
default:
println("no comm")
}
println("bye")
}
// Output:
// no comm
// bye
yaegi-0.10.0/_test/select4.go 0000664 0000000 0000000 00000000332 14120400617 0015667 0 ustar 00root root 0000000 0000000 package main
func main() {
c1 := make(chan string)
go func() { c1 <- "done" }()
select {
case msg1 := <-c1:
println("received from c1:", msg1)
}
println("Bye")
}
// Output:
// received from c1: done
// Bye
yaegi-0.10.0/_test/select5.go 0000664 0000000 0000000 00000000433 14120400617 0015672 0 ustar 00root root 0000000 0000000 package main
type T struct {
c1 chan string
}
func main() {
t := &T{}
t.c1 = make(chan string)
go func(c chan string) { c <- "done" }(t.c1)
select {
case msg1 := <-t.c1:
println("received from c1:", msg1)
}
println("Bye")
}
// Output:
// received from c1: done
// Bye
yaegi-0.10.0/_test/select6.go 0000664 0000000 0000000 00000000406 14120400617 0015673 0 ustar 00root root 0000000 0000000 package main
type T struct {
c1 chan string
}
func main() {
t := &T{}
t.c1 = make(chan string)
go func(c chan string) { c <- "done" }(t.c1)
select {
case <-t.c1:
println("received from c1")
}
println("Bye")
}
// Output:
// received from c1
// Bye
yaegi-0.10.0/_test/select7.go 0000664 0000000 0000000 00000000411 14120400617 0015670 0 ustar 00root root 0000000 0000000 package main
type T struct {
c1 chan string
}
func main() {
t := &T{}
t.c1 = make(chan string)
a := 0
go func() {
select {
case t.c1 <- "done":
a++
}
}()
msg1 := <-t.c1
println("received from c1:", msg1)
}
// Output:
// received from c1: done
yaegi-0.10.0/_test/select8.go 0000664 0000000 0000000 00000000467 14120400617 0015704 0 ustar 00root root 0000000 0000000 package main
type T struct {
c1 chan string
c2 chan string
}
func main() {
t := &T{}
t.c1 = make(chan string)
go func(c chan string) { c <- "done" }(t.c1)
select {
case msg := <-t.c1:
println("received from c1:", msg)
case <-t.c2:
}
println("Bye")
}
// Output:
// received from c1: done
// Bye
yaegi-0.10.0/_test/select9.go 0000664 0000000 0000000 00000000372 14120400617 0015700 0 ustar 00root root 0000000 0000000 package main
type T struct {
c1 chan string
}
func main() {
t := &T{}
t.c1 = make(chan string)
go func() {
select {
case t.c1 <- "done":
}
}()
msg1 := <-t.c1
println("received from c1:", msg1)
}
// Output:
// received from c1: done
yaegi-0.10.0/_test/selector-scope0.go 0000664 0000000 0000000 00000000526 14120400617 0017340 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func test(time string, t time.Time) string {
return time
}
var zero = time.Time{}
func test2(time string) time.Time {
return zero
}
func main() {
str := test("test", time.Now())
fmt.Println(str)
str2 := test2("test2")
fmt.Println(str2)
}
// Output:
// test
// 0001-01-01 00:00:00 +0000 UTC
yaegi-0.10.0/_test/server.go 0000664 0000000 0000000 00000000401 14120400617 0015627 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
var v string = "v1.0"
func main() {
a := "hello "
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Welcome to my website! ", a, v)
})
http.ListenAndServe(":8080", nil)
}
yaegi-0.10.0/_test/server0.go 0000664 0000000 0000000 00000000377 14120400617 0015723 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
var v string = "v1.0"
func myHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Welcome to my website!")
}
func main() {
http.HandleFunc("/", myHandler)
http.ListenAndServe(":8080", nil)
}
yaegi-0.10.0/_test/server1.go 0000664 0000000 0000000 00000000545 14120400617 0015721 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
var version string = "1.0"
type Middleware struct {
Name string
}
func (m *Middleware) Handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Welcome to my website", m.Name, version)
}
func main() {
m := &Middleware{"Test"}
http.HandleFunc("/", m.Handler)
http.ListenAndServe(":8080", nil)
}
yaegi-0.10.0/_test/server1a.go 0000664 0000000 0000000 00000000676 14120400617 0016067 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"log"
"net/http"
)
var v string = "v1.0"
type Middleware struct {
Name string
}
func (m *Middleware) Handler(w http.ResponseWriter, r *http.Request) {
log.Println(r.Header.Get("User-Agent"))
w.Header().Set("test", "ok")
log.Println(w.Header())
fmt.Fprintln(w, "Welcome to my website", m.Name)
}
func main() {
m := &Middleware{"Test"}
http.HandleFunc("/", m.Handler)
http.ListenAndServe(":8080", nil)
}
yaegi-0.10.0/_test/server2.go 0000664 0000000 0000000 00000000406 14120400617 0015716 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
var v string = "v1.0"
func main() {
myHandler := func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Welcome to my website!")
}
http.HandleFunc("/", myHandler)
http.ListenAndServe(":8080", nil)
}
yaegi-0.10.0/_test/server3.go 0000664 0000000 0000000 00000000355 14120400617 0015722 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
)
var myHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("hello world")) })
func main() {
http.HandleFunc("/", myHandler)
http.ListenAndServe(":8080", nil)
}
yaegi-0.10.0/_test/server4.go 0000664 0000000 0000000 00000000317 14120400617 0015721 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Welcome to my website!"))
})
http.ListenAndServe(":8080", nil)
}
yaegi-0.10.0/_test/server5.go 0000664 0000000 0000000 00000000323 14120400617 0015717 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
)
var myHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello world"))
})
func main() {
http.ListenAndServe(":8080", myHandler)
}
yaegi-0.10.0/_test/server6.go 0000664 0000000 0000000 00000000774 14120400617 0015732 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
var myHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello world"))
})
type T1 struct {
Name string
}
func (t *T1) Handler(h http.Handler) http.Handler {
fmt.Println("#1", t.Name)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println("#2", t.Name)
h.ServeHTTP(w, r)
})
}
func main() {
t := &T1{"myName"}
handler := t.Handler(myHandler)
http.ListenAndServe(":8080", handler)
}
yaegi-0.10.0/_test/server7.go 0000664 0000000 0000000 00000000500 14120400617 0015716 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
)
func main() {
http.DefaultServeMux.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {})
http.DefaultServeMux = &http.ServeMux{}
http.DefaultServeMux.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {})
http.DefaultServeMux = &http.ServeMux{}
}
yaegi-0.10.0/_test/shift0.go 0000664 0000000 0000000 00000000174 14120400617 0015525 0 ustar 00root root 0000000 0000000 package main
func main() {
var rounds uint64
var cost uint32 = 2
rounds = 1 << cost
println(rounds)
}
// Output:
// 4
yaegi-0.10.0/_test/shift1.go 0000664 0000000 0000000 00000000171 14120400617 0015523 0 ustar 00root root 0000000 0000000 package main
import "fmt"
const a1 = 0x7f8 >> 3
func main() {
fmt.Printf("%T %v\n", a1, a1)
}
// Output:
// int 255
yaegi-0.10.0/_test/shift2.go 0000664 0000000 0000000 00000000134 14120400617 0015523 0 ustar 00root root 0000000 0000000 package main
func main() {
var u uint64
var v uint32
println(u << v)
}
// Output:
// 0
yaegi-0.10.0/_test/shift3.go 0000664 0000000 0000000 00000000141 14120400617 0015522 0 ustar 00root root 0000000 0000000 package main
const a = 1.0
const b = a + 3
func main() { println(b << (1)) }
// Output:
// 8
yaegi-0.10.0/_test/sieve.go 0000664 0000000 0000000 00000001455 14120400617 0015446 0 ustar 00root root 0000000 0000000 // A concurrent prime sieve
package main
// Send the sequence 2, 3, 4, ... to channel 'ch'.
func Generate(ch chan<- int) {
for i := 2; ; i++ {
ch <- i // Send 'i' to channel 'ch'.
}
}
// Copy the values from channel 'in' to channel 'out',
// removing those divisible by 'prime'.
func Filter(in <-chan int, out chan<- int, prime int) {
for {
i := <-in // Receive value from 'in'.
if i%prime != 0 {
out <- i // Send 'i' to 'out'.
}
}
}
// The prime sieve: Daisy-chain Filter processes.
func main() {
ch := make(chan int) // Create a new channel.
go Generate(ch) // Launch Generate goroutine.
for i := 0; i < 10; i++ {
prime := <-ch
println(prime)
ch1 := make(chan int)
go Filter(ch, ch1, prime)
ch = ch1
}
}
// Output:
// 2
// 3
// 5
// 7
// 11
// 13
// 17
// 19
// 23
// 29
yaegi-0.10.0/_test/slice.go 0000664 0000000 0000000 00000000176 14120400617 0015431 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := [2][2]int{{0, 1}, {2, 3}}
fmt.Println(a[0][0:])
}
// Output:
// [0 1]
yaegi-0.10.0/_test/str.go 0000664 0000000 0000000 00000000121 14120400617 0015130 0 ustar 00root root 0000000 0000000 package main
func main() {
println("hello world")
}
// Output:
// hello world
yaegi-0.10.0/_test/str0.go 0000664 0000000 0000000 00000000304 14120400617 0015213 0 ustar 00root root 0000000 0000000 package main
import "fmt"
const itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
func main() {
fmt.Printf("%v %T\n", itoa64[2], itoa64[2])
}
// Output:
// 48 uint8
yaegi-0.10.0/_test/str1.go 0000664 0000000 0000000 00000000303 14120400617 0015213 0 ustar 00root root 0000000 0000000 package main
const itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
func main() {
for i, r := range itoa64 {
if r == '1' {
println(i)
}
}
}
// Output:
// 3
yaegi-0.10.0/_test/str2.go 0000664 0000000 0000000 00000000255 14120400617 0015222 0 ustar 00root root 0000000 0000000 package main
const itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
func main() {
if itoa64[3] == '1' {
println("ok")
}
}
// Output:
// ok
yaegi-0.10.0/_test/str3.go 0000664 0000000 0000000 00000000166 14120400617 0015224 0 ustar 00root root 0000000 0000000 package main
import "strconv"
func main() {
str := strconv.Itoa(101)
println(str[0] == '1')
}
// Output:
// true
yaegi-0.10.0/_test/str4.go 0000664 0000000 0000000 00000000217 14120400617 0015222 0 ustar 00root root 0000000 0000000 package main
import "unicode/utf8"
func main() {
r, _ := utf8.DecodeRuneInString("Hello")
println(r < utf8.RuneSelf)
}
// Output:
// true
yaegi-0.10.0/_test/struct.go 0000664 0000000 0000000 00000000163 14120400617 0015652 0 ustar 00root root 0000000 0000000 package main
type T struct {
f int
g int
}
func main() {
a := T{7, 8}
println(a.f, a.g)
}
// Output:
// 7 8
yaegi-0.10.0/_test/struct0.go 0000664 0000000 0000000 00000000157 14120400617 0015735 0 ustar 00root root 0000000 0000000 package main
type T struct {
f int
g int
}
func main() {
a := T{}
println(a.f, a.g)
}
// Output:
// 0 0
yaegi-0.10.0/_test/struct0a.go 0000664 0000000 0000000 00000000175 14120400617 0016076 0 ustar 00root root 0000000 0000000 package main
type T struct {
f int
}
func main() {
a := T{}
println(a.f)
a.f = 8
println(a.f)
}
// Output:
// 0
// 8
yaegi-0.10.0/_test/struct1.go 0000664 0000000 0000000 00000000230 14120400617 0015726 0 ustar 00root root 0000000 0000000 package main
type T struct {
f int
g struct {
h int
}
}
func main() {
a := T{}
a.g.h = 3 + 2
println("a.g.h", a.g.h)
}
// Output:
// a.g.h 5
yaegi-0.10.0/_test/struct10.go 0000664 0000000 0000000 00000000165 14120400617 0016015 0 ustar 00root root 0000000 0000000 package main
type T struct {
f int
g int64
}
func main() {
a := T{g: 8}
println(a.f, a.g)
}
// Output:
// 0 8
yaegi-0.10.0/_test/struct11.go 0000664 0000000 0000000 00000000347 14120400617 0016020 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
type Fromage struct {
http.ResponseWriter
}
func main() {
a := Fromage{}
if a.ResponseWriter == nil {
fmt.Println("nil")
} else {
fmt.Println("not nil")
}
}
// Output:
// nil
yaegi-0.10.0/_test/struct12.go 0000664 0000000 0000000 00000000220 14120400617 0016007 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type S1 struct {
Name string
}
type S2 struct {
*S1
}
func main() {
fmt.Println(S2{})
}
// Output:
// {}
yaegi-0.10.0/_test/struct13.go 0000664 0000000 0000000 00000000251 14120400617 0016014 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
type Fromage struct {
http.Server
}
func main() {
a := Fromage{}
fmt.Println(a.Server.WriteTimeout)
}
// Output:
// 0s
yaegi-0.10.0/_test/struct14.go 0000664 0000000 0000000 00000000240 14120400617 0016013 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
type Fromage struct {
*http.Server
}
func main() {
a := Fromage{}
fmt.Println(a.Server)
}
// Output:
//
yaegi-0.10.0/_test/struct15.go 0000664 0000000 0000000 00000000572 14120400617 0016024 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
type GzipResponseWriter struct {
http.ResponseWriter
index int
}
type GzipResponseWriterWithCloseNotify struct {
*GzipResponseWriter
}
func (w GzipResponseWriterWithCloseNotify) CloseNotify() <-chan bool {
return w.ResponseWriter.(http.CloseNotifier).CloseNotify()
}
func main() {
fmt.Println("hello")
}
// Output:
// hello
yaegi-0.10.0/_test/struct16.go 0000664 0000000 0000000 00000000235 14120400617 0016021 0 ustar 00root root 0000000 0000000 package main
type S1 struct {
Name string
}
type S2 struct {
*S1
}
func main() {
s1 := S1{"foo"}
s2 := S2{&s1}
println(s2.Name)
}
// Output:
// foo
yaegi-0.10.0/_test/struct17.go 0000664 0000000 0000000 00000000235 14120400617 0016022 0 ustar 00root root 0000000 0000000 package main
type S1 struct {
Name string
}
type S2 struct {
*S1
}
func main() {
s1 := &S1{"foo"}
s2 := S2{s1}
println(s2.Name)
}
// Output:
// foo
yaegi-0.10.0/_test/struct18.go 0000664 0000000 0000000 00000000355 14120400617 0016026 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
)
type AuthenticatedRequest struct {
http.Request
Username string
}
func main() {
a := &AuthenticatedRequest{}
fmt.Printf("%v %T\n", a.Header, a.Header)
}
// Output:
// map[] http.Header
yaegi-0.10.0/_test/struct19.go 0000664 0000000 0000000 00000000775 14120400617 0016035 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type Config struct {
Users `json:"users,omitempty" mapstructure:","`
UsersFile string `json:"usersFile,omitempty"`
Realm string `json:"realm,omitempty"`
RemoveHeader bool `json:"removeHeader,omitempty"`
HeaderField string `json:"headerField,omitempty" export:"true"`
}
// Users holds a list of users
type Users []string
func CreateConfig() *Config {
return &Config{}
}
func main() {
c := CreateConfig()
fmt.Println(c)
}
// Output:
// &{[] false }
yaegi-0.10.0/_test/struct2.go 0000664 0000000 0000000 00000000171 14120400617 0015733 0 ustar 00root root 0000000 0000000 package main
type T struct {
f int
g int
}
func main() {
a := T{g: 8, f: 7}
println(a.f, a.g)
}
// Output:
// 7 8
yaegi-0.10.0/_test/struct20.go 0000664 0000000 0000000 00000000612 14120400617 0016013 0 ustar 00root root 0000000 0000000 package main
type SecretProvider func(user, realm string) string
type BasicAuth struct {
Realm string
Secrets SecretProvider
}
func (a *BasicAuth) CheckAuth() string { return a.Secrets("me", a.Realm) }
func secretBasic(user, realm string) string { return user + "-" + realm }
func main() {
b := &BasicAuth{"test", secretBasic}
s := b.CheckAuth()
println(s)
}
// Output:
// me-test
yaegi-0.10.0/_test/struct21.go 0000664 0000000 0000000 00000000703 14120400617 0016015 0 ustar 00root root 0000000 0000000 package main
type SecretProvider func(user, realm string) string
type BasicAuth struct {
Realm string
Secrets SecretProvider
}
func (a *BasicAuth) CheckAuth() string { return a.Secrets("me", a.Realm) }
func (a *BasicAuth) secretBasic(user, realm string) string { return a.Realm + "-" + user + "-" + realm }
func main() {
b := &BasicAuth{Realm: "test"}
b.Secrets = b.secretBasic
s := b.CheckAuth()
println(s)
}
// Output:
// test-me-test
yaegi-0.10.0/_test/struct22.go 0000664 0000000 0000000 00000000251 14120400617 0016014 0 ustar 00root root 0000000 0000000 package main
type S struct {
Child *S
Name string
}
func main() {
s := &S{Name: "root"}
s.Child = &S{Name: "child"}
println(s.Child.Name)
}
// Output:
// child
yaegi-0.10.0/_test/struct23.go 0000664 0000000 0000000 00000000732 14120400617 0016021 0 ustar 00root root 0000000 0000000 package main
import (
"encoding/json"
"os"
)
type S struct {
Name string
Child []*S
}
func main() {
a := S{Name: "hello"}
a.Child = append(a.Child, &S{Name: "world"})
json.NewEncoder(os.Stdout).Encode(a)
a.Child[0].Child = append([]*S{}, &S{Name: "sunshine"})
json.NewEncoder(os.Stdout).Encode(a)
}
// Output:
// {"Name":"hello","Child":[{"Name":"world","Child":null}]}
// {"Name":"hello","Child":[{"Name":"world","Child":[{"Name":"sunshine","Child":null}]}]}
yaegi-0.10.0/_test/struct24.go 0000664 0000000 0000000 00000000144 14120400617 0016017 0 ustar 00root root 0000000 0000000 package main
var a = &T{}
type T struct{}
func main() {
println(a != nil)
}
// Output:
// true
yaegi-0.10.0/_test/struct25.go 0000664 0000000 0000000 00000000154 14120400617 0016021 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var a = T{}
type T struct{}
func main() {
fmt.Println(a)
}
// Output:
// {}
yaegi-0.10.0/_test/struct26.go 0000664 0000000 0000000 00000000263 14120400617 0016023 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func newT2() *T2 { return &T2{} }
type T2 struct {
T1
}
type T1 struct {
bs []byte
}
func main() {
fmt.Println(newT2())
}
// Output:
// &{{[]}}
yaegi-0.10.0/_test/struct27.go 0000664 0000000 0000000 00000000315 14120400617 0016022 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func (f *Foo) Boo() { fmt.Println(f.name, "Boo") }
type Foo struct {
name string
fun func(f *Foo)
}
func main() {
t := &Foo{name: "foo"}
t.Boo()
}
// Output:
// foo Boo
yaegi-0.10.0/_test/struct28.go 0000664 0000000 0000000 00000000221 14120400617 0016017 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T1 struct {
T2
}
type T2 struct {
*T1
}
func main() {
t := T1{}
fmt.Println(t)
}
// Output:
// {{}}
yaegi-0.10.0/_test/struct29.go 0000664 0000000 0000000 00000000222 14120400617 0016021 0 ustar 00root root 0000000 0000000 package main
type T1 struct {
A []T2
B []T2
}
type T2 struct {
name string
}
var t = T1{}
func main() {
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/struct3.go 0000664 0000000 0000000 00000000263 14120400617 0015736 0 ustar 00root root 0000000 0000000 package main
type T struct {
f int
g int
h struct {
k int
}
}
func f(i int) int { return i + 3 }
func main() {
a := T{}
a.h.k = f(4)
println(a.h.k)
}
// Output:
// 7
yaegi-0.10.0/_test/struct30.go 0000664 0000000 0000000 00000000233 14120400617 0016013 0 ustar 00root root 0000000 0000000 package main
type T1 struct {
A []T2
M map[uint64]T2
}
type T2 struct {
name string
}
var t = T1{}
func main() {
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/struct31.go 0000664 0000000 0000000 00000000165 14120400617 0016020 0 ustar 00root root 0000000 0000000 package main
type T struct {
bool
}
var t = T{true}
func main() {
println(t.bool && true)
}
// Output:
// true
yaegi-0.10.0/_test/struct32.go 0000664 0000000 0000000 00000000726 14120400617 0016024 0 ustar 00root root 0000000 0000000 package main
type T0 struct {
name string
}
type lookupFunc func(s string) T0
type T1 struct {
name string
info lookupFunc
}
func (t T0) F1() bool { println("in F1"); return true }
type T2 struct {
t1 T1
}
func (t2 *T2) f() {
info := t2.t1.info("foo")
println(info.F1())
}
var t0 = T0{"t0"}
func main() {
t := &T2{T1{
"bar", func(s string) T0 { return t0 },
}}
println("hello")
println(t.t1.info("foo").F1())
}
// Output:
// hello
// in F1
// true
yaegi-0.10.0/_test/struct33.go 0000664 0000000 0000000 00000000651 14120400617 0016022 0 ustar 00root root 0000000 0000000 package main
type T0 struct {
name string
}
type lookupFunc func(s string) T0
type T1 struct {
name string
info lookupFunc
}
func (t T0) F1() bool { println("in F1"); return true }
var t0 = T0{"t0"}
func look(s string) T0 { println("in look"); return t0 }
var table = []*T1{{
name: "bar",
info: look,
},
}
func main() {
info := table[0].info
println(info("foo").F1())
}
// Output:
// in look
// in F1
// true
yaegi-0.10.0/_test/struct34.go 0000664 0000000 0000000 00000000226 14120400617 0016021 0 ustar 00root root 0000000 0000000 package main
type T struct {
f func(*T)
}
func f1(t *T) { t.f = f2 }
func f2(t *T) { t.f = f1 }
func main() {
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/struct35.go 0000664 0000000 0000000 00000000224 14120400617 0016020 0 ustar 00root root 0000000 0000000 package main
type T struct {
f func(*T)
}
func f1(t *T) { t.f = f1 }
func main() {
t := &T{}
f1(t)
println(t.f != nil)
}
// Output:
// true
yaegi-0.10.0/_test/struct36.go 0000664 0000000 0000000 00000000372 14120400617 0016025 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"strings"
)
type S struct {
http.Client
}
func main() {
var s S
if _, err := s.Get("url"); err != nil {
println(strings.Contains(err.Error(), "unsupported protocol scheme"))
}
return
}
// Output:
// true
yaegi-0.10.0/_test/struct37.go 0000664 0000000 0000000 00000000425 14120400617 0016025 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"strings"
)
type MyHttpClient struct {
*http.Client
}
func main() {
c := new(MyHttpClient)
c.Client = new(http.Client)
_, err := c.Get("url")
println(strings.Contains(err.Error(), "unsupported protocol scheme"))
}
// Output:
// true
yaegi-0.10.0/_test/struct38.go 0000664 0000000 0000000 00000000270 14120400617 0016024 0 ustar 00root root 0000000 0000000 package main
type T struct {
f func(t *T1)
y *xxx
}
type T1 struct {
T
}
type xxx struct{}
var (
x1 *T1 = x
x = &T1{}
)
func main() {
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/struct39.go 0000664 0000000 0000000 00000000247 14120400617 0016031 0 ustar 00root root 0000000 0000000 package main
type T struct {
t *T1
y *xxx
}
type T1 struct {
T
}
var x = &T1{}
var t = &T{}
type xxx struct{}
func main() {
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/struct4.go 0000664 0000000 0000000 00000000365 14120400617 0015742 0 ustar 00root root 0000000 0000000 package main
type T3 struct {
k int
}
type T2 struct {
h int
T3
}
type T struct {
f int
g int
T2
}
func f(i int) int { return i * i }
func main() {
a := T{5, 7, T2{f(8), T3{9}}}
println(a.f, a.g, a.h, a.k)
}
// Output:
// 5 7 64 9
yaegi-0.10.0/_test/struct40.go 0000664 0000000 0000000 00000000274 14120400617 0016021 0 ustar 00root root 0000000 0000000 package main
type T struct {
t *T1
y *xxx
}
type T1 struct {
T
}
func f(t *T) { println("in f") }
var x = &T1{}
type xxx struct{}
func main() {
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/struct41.go 0000664 0000000 0000000 00000000335 14120400617 0016020 0 ustar 00root root 0000000 0000000 package main
type Ti func(*T)
type T1 struct {
t Ti
}
type T struct {
t Ti
y *xxx
}
func f(t *T) { println("in f") }
type xxx struct{}
var x = &T1{t: f}
func main() {
x.t = f
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/struct42.go 0000664 0000000 0000000 00000000255 14120400617 0016022 0 ustar 00root root 0000000 0000000 package main
type T struct {
t func(*T)
y *xxx
}
func f(t *T) { println("in f") }
var x = &T{t: f}
type xxx struct{}
func main() {
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/struct43.go 0000664 0000000 0000000 00000000257 14120400617 0016025 0 ustar 00root root 0000000 0000000 package main
type T struct {
t func(*T)
y *xxx
}
func f(t *T) { println("in f") }
type xxx struct{}
func main() {
x := &T{}
x.t = f
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/struct44.go 0000664 0000000 0000000 00000000402 14120400617 0016016 0 ustar 00root root 0000000 0000000 package main
type Ti func(*T) X
type T1 struct {
t Ti
}
type T struct {
t Ti
y *xxx
}
func f(t *T) X { println("in f"); return X{} }
type X struct{ Name string }
type xxx struct{}
var x = &T1{t: f}
func main() {
println("ok")
}
// Output:
// ok
yaegi-0.10.0/_test/struct45.go 0000664 0000000 0000000 00000000212 14120400617 0016016 0 ustar 00root root 0000000 0000000 package main
type T struct {
b bool
}
type T1 struct {
T
}
func main() {
t := &T1{}
t.b = true
println(t.b)
}
// Output:
// true
yaegi-0.10.0/_test/struct46.go 0000664 0000000 0000000 00000000256 14120400617 0016027 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type A struct {
B string
C D
}
type D struct {
E *A
}
func main() {
a := &A{B: "b"}
a.C = D{E: a}
fmt.Println(a.C.E.B)
}
// Output:
// b
yaegi-0.10.0/_test/struct47.go 0000664 0000000 0000000 00000000354 14120400617 0016027 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type A struct {
B string
C D
}
func (a *A) Test() string {
return "test"
}
type D struct {
E *A
}
func main() {
a := &A{B: "b"}
d := D{E: a}
a.C = d
fmt.Println(a.C.E.Test())
}
// Output:
// test
yaegi-0.10.0/_test/struct48.go 0000664 0000000 0000000 00000000566 14120400617 0016035 0 ustar 00root root 0000000 0000000 package main
type List struct {
Next *List
Num int
}
func add(l *List, n int) *List {
if l == nil {
return &List{Num: n}
}
l.Next = add(l.Next, n)
return l
}
func pr(l *List) {
if l == nil {
println("")
return
}
print(l.Num)
pr(l.Next)
}
func main() {
a := add(nil, 0)
pr(a)
a = add(a, 1)
pr(a)
a = add(a, 2)
pr(a)
}
// Output:
// 0
// 01
// 012
yaegi-0.10.0/_test/struct49.go 0000664 0000000 0000000 00000000676 14120400617 0016040 0 ustar 00root root 0000000 0000000 package main
type S struct {
ts map[string][]*T
}
type T struct {
s *S
}
func (c *S) getT(addr string) (t *T, ok bool) {
cns, ok := c.ts[addr]
if !ok || len(cns) == 0 {
return nil, false
}
t = cns[len(cns)-1]
c.ts[addr] = cns[:len(cns)-1]
return t, true
}
func main() {
s := &S{
ts: map[string][]*T{},
}
s.ts["test"] = append(s.ts["test"], &T{s: s})
t , ok:= s.getT("test")
println(t != nil, ok)
}
// Output:
// true true
yaegi-0.10.0/_test/struct5.go 0000664 0000000 0000000 00000000233 14120400617 0015735 0 ustar 00root root 0000000 0000000 package main
type T struct {
f int
g int
}
func f(i int) int { return i * i }
func main() {
a := T{7, f(4)}
println(a.f, a.g)
}
// Output:
// 7 16
yaegi-0.10.0/_test/struct50.go 0000664 0000000 0000000 00000000517 14120400617 0016022 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type Node struct {
Name string
Child []Node
}
func main() {
a := Node{Name: "hello"}
a.Child = append([]Node{}, Node{Name: "world"})
fmt.Println(a)
a.Child[0].Child = append([]Node{}, Node{Name: "sunshine"})
fmt.Println(a)
}
// Output:
// {hello [{world []}]}
// {hello [{world [{sunshine []}]}]}
yaegi-0.10.0/_test/struct51.go 0000664 0000000 0000000 00000000754 14120400617 0016026 0 ustar 00root root 0000000 0000000 package main
import (
"encoding/json"
"os"
)
type Node struct {
Name string
Child [2]*Node
}
func main() {
a := Node{Name: "hello"}
a.Child[0] = &Node{Name: "world"}
json.NewEncoder(os.Stdout).Encode(a)
a.Child[0].Child[0] = &Node{Name: "sunshine"}
json.NewEncoder(os.Stdout).Encode(a)
}
// Output:
// {"Name":"hello","Child":[{"Name":"world","Child":[null,null]},null]}
// {"Name":"hello","Child":[{"Name":"world","Child":[{"Name":"sunshine","Child":[null,null]},null]},null]}
yaegi-0.10.0/_test/struct52.go 0000664 0000000 0000000 00000000643 14120400617 0016024 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type Node struct {
Name string
Child map[string]Node
}
func main() {
a := Node{Name: "hello", Child: map[string]Node{}}
a.Child["1"] = Node{Name: "world", Child: map[string]Node{}}
fmt.Println(a)
a.Child["1"].Child["1"] = Node{Name: "sunshine", Child: map[string]Node{}}
fmt.Println(a)
}
// Output:
// {hello map[1:{world map[]}]}
// {hello map[1:{world map[1:{sunshine map[]}]}]}
yaegi-0.10.0/_test/struct53.go 0000664 0000000 0000000 00000000254 14120400617 0016023 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type T1 struct {
P []*T
}
type T2 struct {
P2 *T
}
type T struct {
*T1
S1 *T
}
func main() {
fmt.Println(T2{})
}
// Output:
// {}
yaegi-0.10.0/_test/struct54.go 0000664 0000000 0000000 00000000331 14120400617 0016020 0 ustar 00root root 0000000 0000000 package main
type S struct {
t *T
}
func newS() *S {
return &S{
t: &T{u: map[string]*U{}},
}
}
type T struct {
u map[string]*U
}
type U struct {
a int
}
func main() {
s := newS()
_ = s
println("ok")
}
yaegi-0.10.0/_test/struct55.go 0000664 0000000 0000000 00000000475 14120400617 0016032 0 ustar 00root root 0000000 0000000 package main
import (
"log"
"os"
)
type Logger struct {
m []*log.Logger
}
func (l *Logger) Infof(format string, args ...interface{}) {
l.m[0].Printf(format, args...)
}
func main() {
l := &Logger{m: []*log.Logger{log.New(os.Stdout, "", log.Lmsgprefix)}}
l.Infof("test %s", "test")
}
// Output:
// test test
yaegi-0.10.0/_test/struct56.go 0000664 0000000 0000000 00000000353 14120400617 0016026 0 ustar 00root root 0000000 0000000 package main
import (
"encoding/json"
"fmt"
)
type A struct {
IA InnerA
}
type InnerA struct {
Timestamp int64
}
func main() {
a := &A{}
b, _ := json.Marshal(a)
fmt.Println(string(b))
}
// Output:
// {"IA":{"Timestamp":0}}
yaegi-0.10.0/_test/struct57.go 0000664 0000000 0000000 00000000341 14120400617 0016024 0 ustar 00root root 0000000 0000000 package main
import (
"encoding/json"
"fmt"
)
type A struct {
InnerA
}
type InnerA struct {
Timestamp int64
}
func main() {
a := &A{}
b, _ := json.Marshal(a)
fmt.Println(string(b))
}
// Output:
// {"Timestamp":0}
yaegi-0.10.0/_test/struct58.go 0000664 0000000 0000000 00000000365 14120400617 0016033 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"reflect"
)
type A struct {
Test string `tag:"test"`
}
func main() {
a := A{}
t := reflect.TypeOf(a)
f, ok := t.FieldByName("Test")
if !ok {
return
}
fmt.Println(f.Tag.Get("tag"))
}
// Output:
// test
yaegi-0.10.0/_test/struct59.go 0000664 0000000 0000000 00000000573 14120400617 0016035 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
type A struct {
B map[string]*B
C map[string]*C
}
type C struct {
D *D
E *E
}
type D struct {
F *F
G []G
}
type E struct {
H []H
F *F
}
type B struct{}
type F struct{}
type G struct{}
type H struct{}
func main() {
conf := &A{
B: make(map[string]*B),
C: make(map[string]*C),
}
fmt.Println(conf)
}
// Output:
// &{map[] map[]}
yaegi-0.10.0/_test/struct6.go 0000664 0000000 0000000 00000000157 14120400617 0015743 0 ustar 00root root 0000000 0000000 package main
type T struct {
f, g int
}
func main() {
a := T{7, 8}
println(a.f, a.g)
}
// Output:
// 7 8
yaegi-0.10.0/_test/struct60.go 0000664 0000000 0000000 00000000243 14120400617 0016017 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
type data struct {
S string
}
func render(v interface{}) {
fmt.Println(v)
}
func main() {
render(data{})
}
// Output:
// {}
yaegi-0.10.0/_test/struct7.go 0000664 0000000 0000000 00000000230 14120400617 0015734 0 ustar 00root root 0000000 0000000 package main
type Opt struct {
b bool
}
type T struct {
i int
opt Opt
}
func main() {
a := T{}
println(a.i, a.opt.b)
}
// Output:
// 0 false
yaegi-0.10.0/_test/struct8.go 0000664 0000000 0000000 00000000372 14120400617 0015744 0 ustar 00root root 0000000 0000000 package main
type T3 struct {
k int
}
type T2 struct {
h int
T3
}
type T struct {
f int
g int
T2
}
func f(i int) int { return i * i }
func main() {
a := T{5, 7, T2{8, T3{9}}}
println(a.f, a.g, a.T2.h, a.T2.T3.k)
}
// Output:
// 5 7 8 9
yaegi-0.10.0/_test/struct9.go 0000664 0000000 0000000 00000000165 14120400617 0015745 0 ustar 00root root 0000000 0000000 package main
type T struct {
f int
g int64
}
func main() {
a := T{7, 8}
println(a.f, a.g)
}
// Output:
// 7 8
yaegi-0.10.0/_test/switch.go 0000664 0000000 0000000 00000000217 14120400617 0015627 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 3
switch a {
case 0:
println(200)
default:
println(a)
case 3:
println(100)
}
}
// Output:
// 100
yaegi-0.10.0/_test/switch0.go 0000664 0000000 0000000 00000000514 14120400617 0015707 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f(i int) bool {
switch i {
case 0:
println(i)
return false
default:
println("not nul")
return true
}
}
func main() {
r0 := f(0)
fmt.Printf("%T %v", r0, r0)
fmt.Println()
r1 := f(1)
fmt.Printf("%T %v", r1, r1)
fmt.Println()
}
// Output:
// 0
// bool false
// not nul
// bool true
yaegi-0.10.0/_test/switch1.go 0000664 0000000 0000000 00000000202 14120400617 0015702 0 ustar 00root root 0000000 0000000 package main
func main() {
i := 1
switch i {
case 0:
println(i)
default:
println("not nul")
}
}
// Output:
// not nul
yaegi-0.10.0/_test/switch10.go 0000664 0000000 0000000 00000000276 14120400617 0015775 0 ustar 00root root 0000000 0000000 package main
func main() {
var i interface{} = "truc"
switch a := i.(type) {
case string:
println("string", a+" ok")
default:
println("unknown")
}
}
// Output:
// string truc ok
yaegi-0.10.0/_test/switch11.go 0000664 0000000 0000000 00000000311 14120400617 0015764 0 ustar 00root root 0000000 0000000 package main
func main() {
var i interface{} = "truc"
switch b := 2; a := i.(type) {
case string:
println("string", a+" ok")
default:
println("unknown", b)
}
}
// Output:
// string truc ok
yaegi-0.10.0/_test/switch12.go 0000664 0000000 0000000 00000000320 14120400617 0015765 0 ustar 00root root 0000000 0000000 package main
func main() {
var i interface{}
switch a := i.(type) {
case string:
println("string", a+" ok")
case nil:
println("i is nil")
default:
println("unknown")
}
}
// Output:
// i is nil
yaegi-0.10.0/_test/switch13.go 0000664 0000000 0000000 00000000333 14120400617 0015772 0 ustar 00root root 0000000 0000000 package main
func main() {
var i interface{}
switch a := i.(type) {
case string:
println("string", a+" ok")
case i:
println("i is dummy")
default:
println("unknown")
}
}
// Error:
// 9:2: i is not a type
yaegi-0.10.0/_test/switch14.go 0000664 0000000 0000000 00000001004 14120400617 0015767 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type fii interface {
Hello()
}
type Boo struct {
Name string
}
type Bir struct {
Boo
}
type Bar struct{}
func (b Bar) Hello() { fmt.Println("b:", b) }
func (b Boo) Hello() {
fmt.Println("Hello", b)
fmt.Println(b.Name)
}
func inCall(foo fii) {
fmt.Println("inCall")
switch a := foo.(type) {
case Boo:
a.Hello()
default:
fmt.Println("a:", a)
}
}
func main() {
boo := Bir{Boo{"foo"}}
inCall(boo)
inCall(Bar{})
}
// Output:
// inCall
// a: {{foo}}
// inCall
// a: {}
yaegi-0.10.0/_test/switch15.go 0000664 0000000 0000000 00000001021 14120400617 0015767 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type fii interface {
Hello()
}
type Boo struct {
Name string
}
type Bir struct {
Boo
}
type Bar struct{}
func (b Bar) Hello() { fmt.Println("b:", b) }
func (b Boo) Hello() {
fmt.Println("Hello", b)
fmt.Println(b.Name)
}
func inCall(foo fii) {
fmt.Println("inCall")
switch a := foo.(type) {
case Boo, Bir:
a.Hello()
default:
fmt.Println("a:", a)
}
}
func main() {
boo := Bir{Boo{"foo"}}
inCall(boo)
inCall(Bar{})
}
// Output:
// inCall
// Hello {foo}
// foo
// inCall
// a: {}
yaegi-0.10.0/_test/switch16.go 0000664 0000000 0000000 00000001014 14120400617 0015772 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type fii interface {
Hello()
}
type Boo struct {
Name string
}
type Bir struct {
Boo
}
type Bar struct{}
func (b Bar) Hello() { fmt.Println("b:", b) }
func (b Boo) Hello() {
fmt.Println("Hello", b)
fmt.Println(b.Name)
}
func inCall(foo fii) {
fmt.Println("inCall")
switch a := foo.(type) {
case Boo, Bir:
a.Hello()
default:
fmt.Println("a:", a)
}
}
func main() {
boo := Boo{"foo"}
inCall(boo)
inCall(Bar{})
}
// Output:
// inCall
// Hello {foo}
// foo
// inCall
// a: {}
yaegi-0.10.0/_test/switch17.go 0000664 0000000 0000000 00000001143 14120400617 0015776 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type fii interface {
Hello()
}
type Boo struct {
Name string
}
type Bir struct {
Boo
}
type Bar struct{}
func (b Bar) Hello() { fmt.Println("b:", b) }
func (b Boo) Hello() {
fmt.Println("Hello", b)
fmt.Println(b.Name)
}
func inCall(foo fii) {
fmt.Println("inCall")
switch a := foo.(type) {
case Boo:
fmt.Println("type Boo")
a.Hello()
case Bir:
fmt.Println("type Bir")
a.Hello()
default:
fmt.Println("a:", a)
}
}
func main() {
boo := Bir{Boo{"foo"}}
inCall(boo)
inCall(Bar{})
}
// Output:
// inCall
// type Bir
// Hello {foo}
// foo
// inCall
// a: {}
yaegi-0.10.0/_test/switch18.go 0000664 0000000 0000000 00000001142 14120400617 0015776 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type fii interface {
Hello()
}
type Bir struct{}
func (b Bir) Yo() {
fmt.Println("Yo", b)
}
func (b Bir) Hello() {
fmt.Println("Hello", b)
}
type Boo struct {
Name string
}
func (b Boo) Hello() {
fmt.Println("Hello", b)
fmt.Println(b.Name)
}
type Bar struct{}
func (b Bar) Hello() { fmt.Println("b:", b) }
func inCall(foo fii) {
fmt.Println("inCall")
switch a := foo.(type) {
case Boo:
a.Hello()
case Bir:
a.Yo()
default:
fmt.Println("a:", a)
}
}
func main() {
boo := Bir{}
inCall(boo)
inCall(Bar{})
}
// Output:
// inCall
// Yo {}
// inCall
// a: {}
yaegi-0.10.0/_test/switch19.go 0000664 0000000 0000000 00000001153 14120400617 0016001 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type fii interface {
Hello()
}
type Bir struct{}
func (b Bir) Yo() {
fmt.Println("Yo", b)
}
func (b Bir) Hello() {
fmt.Println("Hello", b)
}
type Boo struct {
Name string
}
func (b Boo) Hello() {
fmt.Println("Hello", b)
fmt.Println(b.Name)
}
type Bar struct{}
func (b Bar) Hello() { fmt.Println("b:", b) }
func inCall(foo fii) {
fmt.Println("inCall")
switch a := foo.(type) {
case Boo, Bir:
a.Hello()
case Bir:
a.Yo()
default:
fmt.Println("a:", a)
}
}
func main() {
boo := Bir{}
inCall(boo)
inCall(Bar{})
}
// Error:
// 37:2: duplicate case Bir in type switch
yaegi-0.10.0/_test/switch2.go 0000664 0000000 0000000 00000000202 14120400617 0015703 0 ustar 00root root 0000000 0000000 package main
func main() {
i := 1
switch i {
case 0, 1, 2:
println(i)
default:
println("not nul")
}
}
// Output:
// 1
yaegi-0.10.0/_test/switch20.go 0000664 0000000 0000000 00000000224 14120400617 0015767 0 ustar 00root root 0000000 0000000 package main
func main() {
i := 1
switch i {
case 1:
// nothing to do
default:
println("not run")
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/switch21.go 0000664 0000000 0000000 00000000265 14120400617 0015775 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var err error
switch v := err.(type) {
case fmt.Formatter:
println("formatter")
default:
fmt.Println(v)
}
}
// Output:
//
yaegi-0.10.0/_test/switch22.go 0000664 0000000 0000000 00000000337 14120400617 0015776 0 ustar 00root root 0000000 0000000 package main
type T struct {
Name string
}
func f(t interface{}) {
switch ext := t.(type) {
case *T:
println("*T", ext.Name)
default:
println("unknown")
}
}
func main() {
f(&T{"truc"})
}
// Output:
// *T truc
yaegi-0.10.0/_test/switch23.go 0000664 0000000 0000000 00000000251 14120400617 0015772 0 ustar 00root root 0000000 0000000 package main
func getType() string { return "T1" }
func main() {
switch getType() {
case "T1":
println("T1")
default:
println("default")
}
}
// Output:
// T1
yaegi-0.10.0/_test/switch24.go 0000664 0000000 0000000 00000000226 14120400617 0015775 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 3
switch a + 2 {
case 5:
println(5)
default:
println("default")
}
println("bye")
}
// Output:
// 5
// bye
yaegi-0.10.0/_test/switch25.go 0000664 0000000 0000000 00000000260 14120400617 0015774 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 2
switch {
case a == 1:
println(1)
case a == 2:
println(2)
default:
println("default")
}
println("bye")
}
// Output:
// 2
// bye
yaegi-0.10.0/_test/switch26.go 0000664 0000000 0000000 00000000262 14120400617 0015777 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 1
switch a := 2; {
case a == 1:
println(1)
case a == 2:
println(2)
default:
println("default")
}
println(a)
}
// Output:
// 2
// 1
yaegi-0.10.0/_test/switch27.go 0000664 0000000 0000000 00000000251 14120400617 0015776 0 ustar 00root root 0000000 0000000 package main
func main() {
//a := false
switch false {
case true:
println("true")
case false:
println("false")
}
println("bye")
}
// Output:
// false
// bye
yaegi-0.10.0/_test/switch28.go 0000664 0000000 0000000 00000000224 14120400617 0015777 0 ustar 00root root 0000000 0000000 package main
func main() {
switch {
case true:
println("true")
case false:
println("false")
}
println("bye")
}
// Output:
// true
// bye
yaegi-0.10.0/_test/switch29.go 0000664 0000000 0000000 00000000175 14120400617 0016005 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 3
switch a {
case 3:
println("three")
}
println("bye")
}
// Output:
// three
// bye
yaegi-0.10.0/_test/switch3.go 0000664 0000000 0000000 00000000242 14120400617 0015710 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 3
switch a {
case 0:
println(200)
case 3:
println(100)
fallthrough
default:
println(a)
}
}
// Output:
// 100
// 3
yaegi-0.10.0/_test/switch30.go 0000664 0000000 0000000 00000000236 14120400617 0015773 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 3
switch a {
default:
//println("default")
case 3:
println("three")
}
println("bye")
}
// Output:
// three
// bye
yaegi-0.10.0/_test/switch31.go 0000664 0000000 0000000 00000000116 14120400617 0015771 0 ustar 00root root 0000000 0000000 package main
func main() {
switch {
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/switch32.go 0000664 0000000 0000000 00000000135 14120400617 0015773 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 1
switch a {
}
println("bye", a)
}
// Output:
// bye 1
yaegi-0.10.0/_test/switch33.go 0000664 0000000 0000000 00000000152 14120400617 0015773 0 ustar 00root root 0000000 0000000 package main
func main() {
var a interface{}
switch a.(type) {
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/switch34.go 0000664 0000000 0000000 00000000570 14120400617 0016000 0 ustar 00root root 0000000 0000000 package main
func main() {
var a interface{}
a = []int{3}
switch a.(type) {
case []int:
println("a is []int")
case []string:
println("a is []string")
}
var b interface{}
b = []string{"hello"}
switch b.(type) {
case []int:
println("b is []int")
case []string:
println("b is []string")
}
println("bye")
}
// Output:
// a is []int
// b is []string
// bye
yaegi-0.10.0/_test/switch35.go 0000664 0000000 0000000 00000000233 14120400617 0015775 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 2
switch {
case a == 1:
println(1)
case a == 2:
println(2)
default:
}
println("bye")
}
// Output:
// 2
// bye
yaegi-0.10.0/_test/switch36.go 0000664 0000000 0000000 00000000177 14120400617 0016005 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 2
switch {
case a == 1:
println(1)
case a == 2:
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/switch37.go 0000664 0000000 0000000 00000000211 14120400617 0015773 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 2
switch {
case a == 1:
println(1)
case a == 3:
default:
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/switch38.go 0000664 0000000 0000000 00000000646 14120400617 0016010 0 ustar 00root root 0000000 0000000 package main
func isSeparator(c byte) bool {
switch c {
case '(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', '/', '[', ']', '?', '=', '{', '}', ' ', '\t':
return true
}
return false
}
func main() {
s := "max-age=20"
for _, c := range []byte(s) {
println(string(c), isSeparator(c))
}
}
// Output:
// m false
// a false
// x false
// - false
// a false
// g false
// e false
// = true
// 2 false
// 0 false
yaegi-0.10.0/_test/switch4.go 0000664 0000000 0000000 00000000265 14120400617 0015716 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 3
switch b := "foo"; a {
case 0:
println(200)
case 3:
println(100)
fallthrough
default:
println(a, b)
}
}
// Output:
// 100
// 3 foo
yaegi-0.10.0/_test/switch5.go 0000664 0000000 0000000 00000000261 14120400617 0015713 0 ustar 00root root 0000000 0000000 package main
func main() {
i := 1
switch i {
case 0, 1, 2:
if i == 1 {
println("one")
break
}
println(i)
default:
println("not nul")
}
}
// Output:
// one
yaegi-0.10.0/_test/switch6.go 0000664 0000000 0000000 00000000275 14120400617 0015721 0 ustar 00root root 0000000 0000000 package main
func main() {
a := 3
switch b := "foo"; {
case a == 0:
println(200)
case a == 3:
println(100)
fallthrough
default:
println(a, b)
}
}
// Output:
// 100
// 3 foo
yaegi-0.10.0/_test/switch7.go 0000664 0000000 0000000 00000000250 14120400617 0015713 0 ustar 00root root 0000000 0000000 package main
func main() {
var i interface{} = "truc"
switch i.(type) {
case string:
println("string")
default:
println("unknown")
}
}
// Output:
// string
yaegi-0.10.0/_test/switch8.go 0000664 0000000 0000000 00000000205 14120400617 0015714 0 ustar 00root root 0000000 0000000 package main
func main() {
println("hello")
fallthrough
println("world")
}
// Error:
// 5:2: fallthrough statement out of place
yaegi-0.10.0/_test/switch9.go 0000664 0000000 0000000 00000000325 14120400617 0015720 0 ustar 00root root 0000000 0000000 package main
func main() {
var i interface{} = "truc"
switch i.(type) {
case string:
println("string")
fallthrough
default:
println("unknown")
}
}
// Error:
// 9:3: cannot fallthrough in type switch
yaegi-0.10.0/_test/tag0.go 0000664 0000000 0000000 00000000362 14120400617 0015162 0 ustar 00root root 0000000 0000000 // The following comment line has the same effect as 'go run -tags=dummy'
// yaegi:tags dummy
package main
import _ "github.com/traefik/yaegi/_test/ct"
func main() {
println("bye")
}
// Output:
// hello from ct1
// hello from ct3
// bye
yaegi-0.10.0/_test/testdata/ 0000775 0000000 0000000 00000000000 14120400617 0015610 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/testdata/redeclaration-global7/ 0000775 0000000 0000000 00000000000 14120400617 0021751 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/testdata/redeclaration-global7/src/ 0000775 0000000 0000000 00000000000 14120400617 0022540 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/testdata/redeclaration-global7/src/guthib.com/ 0000775 0000000 0000000 00000000000 14120400617 0024577 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/testdata/redeclaration-global7/src/guthib.com/bar/ 0000775 0000000 0000000 00000000000 14120400617 0025343 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/testdata/redeclaration-global7/src/guthib.com/bar/quux.go 0000664 0000000 0000000 00000000063 14120400617 0026673 0 ustar 00root root 0000000 0000000 package quux
func Quux() string {
return "bar"
}
yaegi-0.10.0/_test/testdata/redeclaration-global7/src/guthib.com/baz/ 0000775 0000000 0000000 00000000000 14120400617 0025353 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/testdata/redeclaration-global7/src/guthib.com/baz/quux.go 0000664 0000000 0000000 00000000063 14120400617 0026703 0 ustar 00root root 0000000 0000000 package quux
func Quux() string {
return "baz"
}
yaegi-0.10.0/_test/testdata/redeclaration-global7/src/guthib.com/tata/ 0000775 0000000 0000000 00000000000 14120400617 0025530 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/testdata/redeclaration-global7/src/guthib.com/tata/tutu.go 0000664 0000000 0000000 00000000122 14120400617 0027053 0 ustar 00root root 0000000 0000000 package tutu
import "guthib.com/baz"
func Quux() string {
return quux.Quux()
}
yaegi-0.10.0/_test/testdata/redeclaration-global7/src/guthib.com/toto/ 0000775 0000000 0000000 00000000000 14120400617 0025564 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/testdata/redeclaration-global7/src/guthib.com/toto/titi.go 0000664 0000000 0000000 00000000122 14120400617 0027057 0 ustar 00root root 0000000 0000000 package titi
import "guthib.com/bar"
func Quux() string {
return quux.Quux()
}
yaegi-0.10.0/_test/time0.go 0000664 0000000 0000000 00000000122 14120400617 0015337 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(time.Now())
}
yaegi-0.10.0/_test/time1.go 0000664 0000000 0000000 00000000314 14120400617 0015343 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func main() {
t := time.Date(2009, time.November, 10, 23, 4, 5, 0, time.UTC)
m := t.Minute()
fmt.Println(t, m)
}
// Output:
// 2009-11-10 23:04:05 +0000 UTC 4
yaegi-0.10.0/_test/time10.go 0000664 0000000 0000000 00000000261 14120400617 0015424 0 ustar 00root root 0000000 0000000 package main
import "time"
var UnixTime func(int64, int64) time.Time
func main() {
UnixTime = time.Unix
println(UnixTime(1e9, 0).In(time.UTC).Minute())
}
// Output:
// 46
yaegi-0.10.0/_test/time11.go 0000664 0000000 0000000 00000000240 14120400617 0015422 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
const df = time.Minute * 30
func main() {
fmt.Printf("df: %v %T\n", df, df)
}
// Output:
// df: 30m0s time.Duration
yaegi-0.10.0/_test/time12.go 0000664 0000000 0000000 00000000246 14120400617 0015431 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
var twentyFourHours = time.Duration(24 * time.Hour)
func main() {
fmt.Println(twentyFourHours.Hours())
}
// Output:
// 24
yaegi-0.10.0/_test/time13.go 0000664 0000000 0000000 00000000402 14120400617 0015424 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
var dummy = 1
var t time.Time = time.Date(2007, time.November, 10, 23, 4, 5, 0, time.UTC)
func main() {
t = time.Date(2009, time.November, 10, 23, 4, 5, 0, time.UTC)
fmt.Println(t.Clock())
}
// Output:
// 23 4 5
yaegi-0.10.0/_test/time14.go 0000664 0000000 0000000 00000000271 14120400617 0015431 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
var t time.Time
func f() time.Time {
time := t
return time
}
func main() {
fmt.Println(f())
}
// Output:
// 0001-01-01 00:00:00 +0000 UTC
yaegi-0.10.0/_test/time15.go 0000664 0000000 0000000 00000000266 14120400617 0015436 0 ustar 00root root 0000000 0000000 package main
import "time"
type TimeValue time.Time
func (v *TimeValue) decode() { println("in decode") }
func main() {
var tv TimeValue
tv.decode()
}
// Output:
// in decode
yaegi-0.10.0/_test/time16.go 0000664 0000000 0000000 00000000202 14120400617 0015425 0 ustar 00root root 0000000 0000000 package main
import "time"
func main() {
localTime := time.ANSIC
println(localTime)
}
// Output:
// Mon Jan _2 15:04:05 2006
yaegi-0.10.0/_test/time2.go 0000664 0000000 0000000 00000000273 14120400617 0015350 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func main() {
t := time.Date(2009, time.November, 10, 23, 4, 5, 0, time.UTC)
h, m, s := t.Clock()
fmt.Println(h, m, s)
}
// Output:
// 23 4 5
yaegi-0.10.0/_test/time3.go 0000664 0000000 0000000 00000000311 14120400617 0015342 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
// FIXME related to named returns
func main() {
t := time.Date(2009, time.November, 10, 23, 4, 5, 0, time.UTC)
fmt.Println(t.Clock())
}
// Output:
// 23 4 5
yaegi-0.10.0/_test/time4.go 0000664 0000000 0000000 00000000173 14120400617 0015351 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func main() {
var m time.Month
m = 9
fmt.Println(m)
}
// Output:
// September
yaegi-0.10.0/_test/time5.go 0000664 0000000 0000000 00000000211 14120400617 0015343 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func main() {
t := time.Unix(1e9, 0).In(time.UTC)
fmt.Println(t.Minute())
}
// Output:
// 46
yaegi-0.10.0/_test/time6.go 0000664 0000000 0000000 00000000301 14120400617 0015344 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func main() {
t := &time.Time{}
t.UnmarshalText([]byte("1985-04-12T23:20:50.52Z"))
fmt.Println(t)
}
// Output:
// 1985-04-12 23:20:50.52 +0000 UTC
yaegi-0.10.0/_test/time7.go 0000664 0000000 0000000 00000000163 14120400617 0015353 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
var d = 2 * time.Second
func main() { fmt.Println(d) }
// Output:
// 2s
yaegi-0.10.0/_test/time8.go 0000664 0000000 0000000 00000000341 14120400617 0015352 0 ustar 00root root 0000000 0000000 package main
import (
"time"
)
type durationValue time.Duration
func (d *durationValue) String() string { return (*time.Duration)(d).String() }
func main() {
var d durationValue
println(d.String())
}
// Output:
// 0s
yaegi-0.10.0/_test/time9.go 0000664 0000000 0000000 00000000166 14120400617 0015360 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func main() {
fmt.Println((5 * time.Minute).Seconds())
}
// Output:
// 300
yaegi-0.10.0/_test/type0.go 0000664 0000000 0000000 00000000132 14120400617 0015363 0 ustar 00root root 0000000 0000000 package main
type newInt int
func main() {
var a newInt
println(a)
}
// Output:
// 0
yaegi-0.10.0/_test/type1.go 0000664 0000000 0000000 00000000177 14120400617 0015375 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var i interface{} = "hello"
s := i.(string)
fmt.Println(s)
}
// Output:
// hello
yaegi-0.10.0/_test/type10.go 0000664 0000000 0000000 00000000601 14120400617 0015445 0 ustar 00root root 0000000 0000000 package main
import (
"compress/gzip"
"fmt"
"sync"
)
var gzipWriterPools [10]*sync.Pool = [10]*sync.Pool{}
func main() {
level := 9
gzipWriterPools[level] = &sync.Pool{
New: func() interface{} {
w, _ := gzip.NewWriterLevel(nil, level)
return w
},
}
gzw := gzipWriterPools[level].Get().(*gzip.Writer)
fmt.Printf("gzw: %T\n", gzw)
}
// Output:
// gzw: *gzip.Writer
yaegi-0.10.0/_test/type11.go 0000664 0000000 0000000 00000000330 14120400617 0015445 0 ustar 00root root 0000000 0000000 package main
import (
"compress/gzip"
"fmt"
"sync"
)
var gzipWriterPools [gzip.BestCompression - gzip.BestSpeed + 2]*sync.Pool
func main() {
fmt.Printf("%T\n", gzipWriterPools)
}
// Output:
// [10]*sync.Pool
yaegi-0.10.0/_test/type12.go 0000664 0000000 0000000 00000000456 14120400617 0015457 0 ustar 00root root 0000000 0000000 package main
type T1 struct {
T2 *T2
}
func (t *T1) Get() string {
return t.T2.V().Name
}
type T2 struct {
Name string
}
func (t *T2) V() *T2 {
if t == nil {
return defaultT2
}
return t
}
var defaultT2 = &T2{"no name"}
func main() {
t := &T1{}
println(t.Get())
}
// Output:
// no name
yaegi-0.10.0/_test/type13.go 0000664 0000000 0000000 00000000144 14120400617 0015452 0 ustar 00root root 0000000 0000000 package main
var a = &T{}
type T struct{}
func main() {
println(a != nil)
}
// Output:
// true
yaegi-0.10.0/_test/type14.go 0000664 0000000 0000000 00000000154 14120400617 0015454 0 ustar 00root root 0000000 0000000 package main
import "fmt"
var a = T{}
type T struct{}
func main() {
fmt.Println(a)
}
// Output:
// {}
yaegi-0.10.0/_test/type15.go 0000664 0000000 0000000 00000000132 14120400617 0015451 0 ustar 00root root 0000000 0000000 package main
func main() {
err := error(nil)
println(err == nil)
}
// Output:
// true
yaegi-0.10.0/_test/type16.go 0000664 0000000 0000000 00000000173 14120400617 0015457 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := uint8(15) ^ byte(0)
fmt.Printf("%T %v\n", a, a)
}
// Output:
// uint8 15
yaegi-0.10.0/_test/type17.go 0000664 0000000 0000000 00000000173 14120400617 0015460 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
a := int32(15) ^ rune(0)
fmt.Printf("%T %v\n", a, a)
}
// Output:
// int32 15
yaegi-0.10.0/_test/type18.go 0000664 0000000 0000000 00000000253 14120400617 0015460 0 ustar 00root root 0000000 0000000 package main
type T struct {
name string
size int
}
var table = []*T{{
name: "foo",
size: 2,
}}
var s = table[0].size
func main() {
println(s)
}
// Output:
// 2
yaegi-0.10.0/_test/type19.go 0000664 0000000 0000000 00000000271 14120400617 0015461 0 ustar 00root root 0000000 0000000 package main
type T struct {
name string
size int
}
var table = map[int]*T{
0: {
name: "foo",
size: 2,
}}
var s = table[0].size
func main() {
println(s)
}
// Output:
// 2
yaegi-0.10.0/_test/type2.go 0000664 0000000 0000000 00000000441 14120400617 0015370 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
type Options struct {
debug bool
}
type T1 struct {
opt Options
time time.Time
}
func main() {
t := T1{}
t.time = time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
fmt.Println(t.time)
}
// Output:
// 2009-11-10 23:00:00 +0000 UTC
yaegi-0.10.0/_test/type20.go 0000664 0000000 0000000 00000000306 14120400617 0015450 0 ustar 00root root 0000000 0000000 package main
import (
"io"
"strings"
)
func isCloser(r io.Reader) bool {
_, ok := r.(io.Closer)
return ok
}
func main() {
println(isCloser(strings.NewReader("test")))
}
// Output:
// false
yaegi-0.10.0/_test/type21.go 0000664 0000000 0000000 00000000374 14120400617 0015456 0 ustar 00root root 0000000 0000000 package main
import (
"reflect"
"time"
)
func main() {
t := time.Date(2009, time.November, 10, 23, 4, 5, 0, time.UTC)
v := reflect.ValueOf(t.String)
f := v.Interface().(func() string)
println(f())
}
// Output:
// 2009-11-10 23:04:05 +0000 UTC
yaegi-0.10.0/_test/type22.go 0000664 0000000 0000000 00000000231 14120400617 0015447 0 ustar 00root root 0000000 0000000 package main
type T1 T
func foo() T1 {
return T1(T{"foo"})
}
type T struct {
Name string
}
func main() {
println(foo().Name)
}
// Output:
// foo
yaegi-0.10.0/_test/type23.go 0000664 0000000 0000000 00000001124 14120400617 0015452 0 ustar 00root root 0000000 0000000 package main
import (
"net/http"
"net/http/httptest"
)
func main() {
var v1 interface{} = 1
var v2 interface{}
var v3 http.ResponseWriter = httptest.NewRecorder()
if r1, ok := v1.(string); ok {
_ = r1
println("unexpected")
}
if _, ok := v1.(string); ok {
println("unexpected")
}
if r2, ok := v2.(string); ok {
_ = r2
println("unexpected")
}
if _, ok := v2.(string); ok {
println("unexpected")
}
if r3, ok := v3.(http.Pusher); ok {
_ = r3
println("unexpected")
}
if _, ok := v3.(http.Pusher); ok {
println("unexpected")
}
println("bye")
}
// Output:
// bye
yaegi-0.10.0/_test/type24.go 0000664 0000000 0000000 00000001343 14120400617 0015456 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"net/http"
"net/http/httptest"
)
func main() {
assertInt()
assertNil()
assertValue()
}
func assertInt() {
defer func() {
r := recover()
fmt.Println(r)
}()
var v interface{} = 1
println(v.(string))
}
func assertNil() {
defer func() {
r := recover()
fmt.Println(r)
}()
var v interface{}
println(v.(string))
}
func assertValue() {
defer func() {
r := recover()
fmt.Println(r)
}()
var v http.ResponseWriter = httptest.NewRecorder()
println(v.(http.Pusher))
}
// Output:
// interface conversion: interface {} is int, not string
// interface conversion: interface {} is nil, not string
// interface conversion: *httptest.ResponseRecorder is not http.Pusher: missing method Push
yaegi-0.10.0/_test/type25.go 0000664 0000000 0000000 00000001130 14120400617 0015451 0 ustar 00root root 0000000 0000000 package main
import (
"errors"
"sync/atomic"
)
type wrappedError struct {
wrapped error
}
func (e wrappedError) Error() string {
return "some outer error"
}
func (e wrappedError) Unwrap() error {
return e.wrapped
}
var err atomic.Value
func getWrapped() *wrappedError {
if v := err.Load(); v != nil {
err := v.(wrappedError)
if err.wrapped != nil {
return &err
}
}
return nil
}
func main() {
err.Store(wrappedError{wrapped: errors.New("test")})
e := getWrapped()
if e != nil {
println(e.Error())
println(e.wrapped.Error())
}
}
// Output:
// some outer error
// test
yaegi-0.10.0/_test/type26.go 0000664 0000000 0000000 00000001133 14120400617 0015455 0 ustar 00root root 0000000 0000000 package main
import (
"errors"
"sync/atomic"
)
type wrappedError struct {
wrapped error
}
func (e *wrappedError) Error() string {
return "some outer error"
}
func (e *wrappedError) Unwrap() error {
return e.wrapped
}
var err atomic.Value
func getWrapped() *wrappedError {
if v := err.Load(); v != nil {
err := v.(*wrappedError)
if err.wrapped != nil {
return err
}
}
return nil
}
func main() {
err.Store(&wrappedError{wrapped: errors.New("test")})
e := getWrapped()
if e != nil {
println(e.Error())
println(e.wrapped.Error())
}
}
// Output:
// some outer error
// test
yaegi-0.10.0/_test/type3.go 0000664 0000000 0000000 00000000163 14120400617 0015372 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type S1 string
func main() {
s := S1("Hello")
fmt.Println(s)
}
// Output:
// Hello
yaegi-0.10.0/_test/type4.go 0000664 0000000 0000000 00000000201 14120400617 0015364 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"reflect"
)
func main() {
a := int32(12)
fmt.Println(reflect.TypeOf(a))
}
// Output:
// int32
yaegi-0.10.0/_test/type5.go 0000664 0000000 0000000 00000000207 14120400617 0015373 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"reflect"
)
type T int
func main() {
a := T(12)
fmt.Println(reflect.TypeOf(a))
}
// Output:
// int
yaegi-0.10.0/_test/type6.go 0000664 0000000 0000000 00000000207 14120400617 0015374 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"reflect"
)
func main() {
a := T(12)
fmt.Println(reflect.TypeOf(a))
}
type T int
// Output:
// int
yaegi-0.10.0/_test/type7.go 0000664 0000000 0000000 00000000231 14120400617 0015372 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var i interface{} = "hello"
if s, ok := i.(string); ok {
fmt.Println(s, ok)
}
}
// Output:
// hello true
yaegi-0.10.0/_test/type8.go 0000664 0000000 0000000 00000000166 14120400617 0015402 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func main() {
v := (*time.Time)(nil)
fmt.Println(v)
}
// Output:
//
yaegi-0.10.0/_test/type9.go 0000664 0000000 0000000 00000000306 14120400617 0015377 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type Hello struct {
Goodbye GoodbyeProvider
}
func main() {
a := &Hello{}
fmt.Println(a)
}
type GoodbyeProvider func(message string) string
// Output:
// &{}
yaegi-0.10.0/_test/unsafe0.go 0000664 0000000 0000000 00000000231 14120400617 0015663 0 ustar 00root root 0000000 0000000 package main
import "unsafe"
func main() {
str := "foobar"
p := unsafe.Pointer(&str)
str2 := *(*string)(p)
println(str2)
}
// Output:
// foobar
yaegi-0.10.0/_test/unsafe1.go 0000664 0000000 0000000 00000000272 14120400617 0015671 0 ustar 00root root 0000000 0000000 package main
import "unsafe"
type S struct {
Name string
}
func main() {
s := &S{Name: "foobar"}
p := unsafe.Pointer(s)
s2 := (*S)(p)
println(s2.Name)
}
// Output:
// foobar
yaegi-0.10.0/_test/unsafe2.go 0000664 0000000 0000000 00000000337 14120400617 0015674 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"unsafe"
)
func main() {
str := "foobar"
ptr := unsafe.Pointer(&str)
p := uintptr(ptr)
s1 := fmt.Sprintf("%x", ptr)
s2 := fmt.Sprintf("%x", p)
println(s1 == s2)
}
// Output:
// true
yaegi-0.10.0/_test/unsafe3.go 0000664 0000000 0000000 00000000651 14120400617 0015674 0 ustar 00root root 0000000 0000000 package main
import (
"math/bits"
"unsafe"
)
const (
SSize = 16
WSize = bits.UintSize / 8
)
type S struct {
X int
Y int
}
func main() {
bigEndian := (*(*[2]uint8)(unsafe.Pointer(&[]uint16{1}[0])))[0] == 0
var sBuf [SSize]byte
s := (*S)(unsafe.Pointer(&sBuf[0]))
s.X = 2
s.Y = 4
if bigEndian {
println(sBuf[0+WSize-1], sBuf[WSize+WSize-1])
} else {
println(sBuf[0], sBuf[WSize])
}
}
// Output:
// 2 4
yaegi-0.10.0/_test/unsafe4.go 0000664 0000000 0000000 00000000561 14120400617 0015675 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/bits"
"unsafe"
)
const WSize = bits.UintSize / 8
type S struct {
X int
Y int
Z int
}
func main() {
arr := []S{
{X: 1},
{X: 2},
{X: 3},
}
addr := unsafe.Pointer(&arr[0])
// s := *(*S)(unsafe.Pointer(uintptr(addr) + SSize*2))
s := *(*S)(unsafe.Pointer(uintptr(addr) + WSize*6))
fmt.Println(s.X)
}
// Output:
// 3
yaegi-0.10.0/_test/unsafe5.go 0000664 0000000 0000000 00000000470 14120400617 0015675 0 ustar 00root root 0000000 0000000 package main
import (
"math/bits"
"unsafe"
)
const WSize = bits.UintSize / 8
type S struct {
X int
Y int
Z int
}
func main() {
x := S{}
size := unsafe.Sizeof(x) / WSize
align := unsafe.Alignof(x.Y) / WSize
offset := unsafe.Offsetof(x.Z) / WSize
println(size, align, offset)
}
// Output:
// 3 1 2
yaegi-0.10.0/_test/unsafe6.go 0000664 0000000 0000000 00000000362 14120400617 0015676 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"unsafe"
)
type S struct {
X int
Y int
Z int
}
func main() {
x := S{Z: 5}
ptr := unsafe.Pointer(&x)
offset := int(unsafe.Offsetof(x.Z))
p := unsafe.Add(ptr, offset)
i := *(*int)(p)
fmt.Println(i)
}
yaegi-0.10.0/_test/unsafe7.go 0000664 0000000 0000000 00000000256 14120400617 0015701 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"unsafe"
)
type S struct {
X int
Y int
Z int
}
func main() {
x := [2]S{{Z: 5}, {Z: 10}}
s := unsafe.Slice(&x[0], 2)
fmt.Println(s)
}
yaegi-0.10.0/_test/var.go 0000664 0000000 0000000 00000000126 14120400617 0015115 0 ustar 00root root 0000000 0000000 package main
func main() {
var a, b, c int
println(a, b, c)
}
// Output:
// 0 0 0
yaegi-0.10.0/_test/var10.go 0000664 0000000 0000000 00000000143 14120400617 0015255 0 ustar 00root root 0000000 0000000 package main
var _ = true
var _ = "hello"
func main() {
println("hello")
}
// Output:
// hello
yaegi-0.10.0/_test/var11.go 0000664 0000000 0000000 00000000144 14120400617 0015257 0 ustar 00root root 0000000 0000000 package main
var a, _, _, b = 1, true, "foo", 2
func main() {
println(a, b)
}
// Output:
// 1 2
yaegi-0.10.0/_test/var12.go 0000664 0000000 0000000 00000000134 14120400617 0015257 0 ustar 00root root 0000000 0000000 package main
var (
a = b
b = "hello"
)
func main() {
println(a)
}
// Output:
// hello
yaegi-0.10.0/_test/var13.go 0000664 0000000 0000000 00000000366 14120400617 0015267 0 ustar 00root root 0000000 0000000 package main
var (
a = concat("hello", b)
b = concat(" ", c, "!")
c = d
d = "world"
)
func concat(a ...string) string {
var s string
for _, ss := range a {
s += ss
}
return s
}
func main() {
println(a)
}
// Output:
// hello world!
yaegi-0.10.0/_test/var14.go 0000664 0000000 0000000 00000000171 14120400617 0015262 0 ustar 00root root 0000000 0000000 package main
import "github.com/traefik/yaegi/_test/vars"
func main() {
println(vars.A)
}
// Output:
// hello world!
yaegi-0.10.0/_test/var15.go 0000664 0000000 0000000 00000000156 14120400617 0015266 0 ustar 00root root 0000000 0000000 package main
var a int = 2
func inca() {
a = a + 1
}
func main() {
inca()
println(a)
}
// Output:
// 3
yaegi-0.10.0/_test/var2.go 0000664 0000000 0000000 00000000112 14120400617 0015172 0 ustar 00root root 0000000 0000000 package main
func main() {
var a int = 2
println(a)
}
// Output:
// 2
yaegi-0.10.0/_test/var3.go 0000664 0000000 0000000 00000000125 14120400617 0015177 0 ustar 00root root 0000000 0000000 package main
func main() {
var a, b int = 2, 3
println(a, b)
}
// Output:
// 2 3
yaegi-0.10.0/_test/var4.go 0000664 0000000 0000000 00000000121 14120400617 0015174 0 ustar 00root root 0000000 0000000 package main
func main() {
var a, b = 2, 3
println(a, b)
}
// Output:
// 2 3
yaegi-0.10.0/_test/var5.go 0000664 0000000 0000000 00000000206 14120400617 0015201 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a int64 = 64
fmt.Printf("a: %v %T", a, a)
fmt.Println()
}
// Output:
// a: 64 int64
yaegi-0.10.0/_test/var6.go 0000664 0000000 0000000 00000000426 14120400617 0015206 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
type Foo struct {
A string
}
var f = Foo{"world"} // <-- the root cause
func Hello() {
fmt.Println("in")
}
var name = "v1" // <-- the root cause
func main() {
Hello()
fmt.Println("Hello", f.A, name)
}
// Output:
// in
// Hello world v1
yaegi-0.10.0/_test/var7.go 0000664 0000000 0000000 00000000223 14120400617 0015202 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
type T struct {
Name string
}
var m = make(map[string]*T)
func main() {
fmt.Println(m)
}
// Output:
// map[]
yaegi-0.10.0/_test/var8.go 0000664 0000000 0000000 00000000335 14120400617 0015207 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"reflect"
)
type Message struct {
Name string
}
var protoMessageType = reflect.TypeOf((*Message)(nil)).Elem()
func main() {
fmt.Println(protoMessageType.Kind())
}
// Output:
// struct
yaegi-0.10.0/_test/var9.go 0000664 0000000 0000000 00000000140 14120400617 0015202 0 ustar 00root root 0000000 0000000 package main
var a = "sdofjsdfj"
var z = a[0:2]
func main() {
println(z)
}
// Output:
// sd
yaegi-0.10.0/_test/variadic.go 0000664 0000000 0000000 00000000172 14120400617 0016110 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f(a ...int) {
fmt.Println(a)
}
func main() {
f(1, 2, 3, 4)
}
// Output:
// [1 2 3 4]
yaegi-0.10.0/_test/variadic0.go 0000664 0000000 0000000 00000000203 14120400617 0016163 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f(s string, a ...int) {
fmt.Println(s, a)
}
func main() {
f("hello")
}
// Output:
// hello []
yaegi-0.10.0/_test/variadic1.go 0000664 0000000 0000000 00000000223 14120400617 0016166 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f(s string, a ...int32) {
fmt.Println(s, a)
}
func main() {
f("hello", 1, 2, 3)
}
// Output:
// hello [1 2 3]
yaegi-0.10.0/_test/variadic10.go 0000664 0000000 0000000 00000000376 14120400617 0016257 0 ustar 00root root 0000000 0000000 package main
import (
"log"
"os"
)
func main() {
logger := log.New(os.Stdout, "test ", log.Lmsgprefix)
logger.Printf("args: %v %v", 1, "truc")
logger.Printf("args: %v %v %v", 1, "truc", 2)
}
// Output:
// test args: 1 truc
// test args: 1 truc 2
yaegi-0.10.0/_test/variadic2.go 0000664 0000000 0000000 00000000212 14120400617 0016165 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f(a ...int) {
if len(a) > 2 {
fmt.Println(a[2])
}
}
func main() {
f(1, 2, 3, 4)
}
// Output:
// 3
yaegi-0.10.0/_test/variadic3.go 0000664 0000000 0000000 00000000314 14120400617 0016171 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func f(a ...int) int {
fmt.Println(a)
res := 0
for _, v := range a {
res += v
}
return res
}
func main() {
fmt.Println(f(1, 2, 3, 4))
}
// Output:
// [1 2 3 4]
// 10
yaegi-0.10.0/_test/variadic4.go 0000664 0000000 0000000 00000000205 14120400617 0016171 0 ustar 00root root 0000000 0000000 package main
func variadic(s ...string) {}
func f(s string) { println(s + "bar") }
func main() { f("foo") }
// Output:
// foobar
yaegi-0.10.0/_test/variadic5.go 0000664 0000000 0000000 00000000273 14120400617 0016177 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
)
type A struct {
}
func (a A) f(vals ...bool) {
for _, v := range vals {
fmt.Println(v)
}
}
func main() {
a := A{}
a.f(true)
}
// Output:
// true
yaegi-0.10.0/_test/variadic6.go 0000664 0000000 0000000 00000000320 14120400617 0016171 0 ustar 00root root 0000000 0000000 package main
import "fmt"
type A struct {
}
func (a A) f(vals ...bool) {
for _, v := range vals {
fmt.Println(v)
}
}
func main() {
bools := []bool{true}
a := A{}
a.f(bools...)
}
// Output:
// true
yaegi-0.10.0/_test/variadic7.go 0000664 0000000 0000000 00000000425 14120400617 0016200 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func main() {
var a, b string
pattern := "%s %s"
dest := []interface{}{&a, &b}
n, err := fmt.Sscanf("test1 test2", pattern, dest...)
if err != nil || n != len(dest) {
println("error")
return
}
println(a, b)
}
// Output:
// test1 test2
yaegi-0.10.0/_test/variadic8.go 0000664 0000000 0000000 00000000276 14120400617 0016205 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
)
func main() {
fn1 := func(args ...*time.Duration) string {
return ""
}
fmt.Printf("%T\n", fn1)
}
// Output:
// func(...*time.Duration) string
yaegi-0.10.0/_test/variadic9.go 0000664 0000000 0000000 00000000320 14120400617 0016174 0 ustar 00root root 0000000 0000000 package main
import "fmt"
func Sprintf(format string, a ...interface{}) string {
return fmt.Sprintf(format, a...)
}
func main() {
fmt.Println(Sprintf("Hello %s", "World!"))
}
// Output:
// Hello World!
yaegi-0.10.0/_test/vars/ 0000775 0000000 0000000 00000000000 14120400617 0014752 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/_test/vars/first.go 0000664 0000000 0000000 00000000227 14120400617 0016431 0 ustar 00root root 0000000 0000000 package vars
var (
A = concat("hello", B)
C = D
)
func concat(a ...string) string {
var s string
for _, ss := range a {
s += ss
}
return s
}
yaegi-0.10.0/_test/vars/second.go 0000664 0000000 0000000 00000000074 14120400617 0016555 0 ustar 00root root 0000000 0000000 package vars
var (
B = concat(" ", C, "!")
D = "world"
)
yaegi-0.10.0/cmd/ 0000775 0000000 0000000 00000000000 14120400617 0013424 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/cmd/yaegi/ 0000775 0000000 0000000 00000000000 14120400617 0014522 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/cmd/yaegi/extract.go 0000664 0000000 0000000 00000004631 14120400617 0016527 0 ustar 00root root 0000000 0000000 package main
import (
"bufio"
"bytes"
"flag"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"github.com/traefik/yaegi/extract"
)
func extractCmd(arg []string) error {
var licensePath string
var name string
var exclude string
var include string
eflag := flag.NewFlagSet("run", flag.ContinueOnError)
eflag.StringVar(&licensePath, "license", "", "path to a LICENSE file")
eflag.StringVar(&name, "name", "", "the namespace for the extracted symbols")
eflag.StringVar(&exclude, "exclude", "", "comma separated list of regexp matching symbols to exclude")
eflag.StringVar(&include, "include", "", "comma separated list of regexp matching symbols to include")
eflag.Usage = func() {
fmt.Println("Usage: yaegi extract [options] packages...")
fmt.Println("Options:")
eflag.PrintDefaults()
}
if err := eflag.Parse(arg); err != nil {
return err
}
args := eflag.Args()
if len(args) == 0 {
return fmt.Errorf("missing package")
}
license, err := genLicense(licensePath)
if err != nil {
return err
}
wd, err := os.Getwd()
if err != nil {
return err
}
if name == "" {
name = filepath.Base(wd)
}
ext := extract.Extractor{
Dest: name,
License: license,
}
if exclude != "" {
ext.Exclude = strings.Split(exclude, ",")
}
if include != "" {
ext.Include = strings.Split(include, ",")
}
r := strings.NewReplacer("/", "-", ".", "_")
for _, pkgIdent := range args {
var buf bytes.Buffer
importPath, err := ext.Extract(pkgIdent, name, &buf)
if err != nil {
fmt.Fprintln(os.Stderr, err)
continue
}
oFile := r.Replace(importPath) + ".go"
f, err := os.Create(oFile)
if err != nil {
return err
}
if _, err := io.Copy(f, &buf); err != nil {
_ = f.Close()
return err
}
if err := f.Close(); err != nil {
return err
}
}
return nil
}
// genLicense generates the correct LICENSE header text from the provided
// path to a LICENSE file.
func genLicense(fname string) (string, error) {
if fname == "" {
return "", nil
}
f, err := os.Open(fname)
if err != nil {
return "", fmt.Errorf("could not open LICENSE file: %w", err)
}
defer func() { _ = f.Close() }()
license := new(strings.Builder)
sc := bufio.NewScanner(f)
for sc.Scan() {
txt := sc.Text()
if txt != "" {
txt = " " + txt
}
license.WriteString("//" + txt + "\n")
}
if sc.Err() != nil {
return "", fmt.Errorf("could not scan LICENSE file: %w", err)
}
return license.String(), nil
}
yaegi-0.10.0/cmd/yaegi/help.go 0000664 0000000 0000000 00000001716 14120400617 0016006 0 ustar 00root root 0000000 0000000 package main
import "fmt"
const usage = `Yaegi is a Go interpreter.
Usage:
yaegi [command] [arguments]
The commands are:
extract generate a wrapper file from a source package
help print usage information
run execute a Go program from source
test execute test functions in a Go package
version print version
Use "yaegi help " for more information about a command.
If no command is given or if the first argument is not a command, then
the run command is assumed.
`
func help(arg []string) error {
var cmd string
if len(arg) > 0 {
cmd = arg[0]
}
switch cmd {
case Extract:
return extractCmd([]string{"-h"})
case Help, "", "-h", "--help":
fmt.Print(usage)
return nil
case Run:
return run([]string{"-h"})
case Test:
return test([]string{"-h"})
case Version:
fmt.Println("Usage: yaegi version")
return nil
default:
return fmt.Errorf("help: invalid yaegi command: %v", cmd)
}
}
yaegi-0.10.0/cmd/yaegi/run.go 0000664 0000000 0000000 00000007766 14120400617 0015675 0 ustar 00root root 0000000 0000000 package main
import (
"flag"
"fmt"
"go/build"
"io/ioutil"
"os"
"reflect"
"strconv"
"strings"
"github.com/traefik/yaegi/interp"
"github.com/traefik/yaegi/stdlib"
"github.com/traefik/yaegi/stdlib/syscall"
"github.com/traefik/yaegi/stdlib/unrestricted"
"github.com/traefik/yaegi/stdlib/unsafe"
)
func run(arg []string) error {
var interactive bool
var noAutoImport bool
var tags string
var cmd string
var err error
// The following flags are initialized from environment.
useSyscall, _ := strconv.ParseBool(os.Getenv("YAEGI_SYSCALL"))
useUnrestricted, _ := strconv.ParseBool(os.Getenv("YAEGI_UNRESTRICTED"))
useUnsafe, _ := strconv.ParseBool(os.Getenv("YAEGI_UNSAFE"))
rflag := flag.NewFlagSet("run", flag.ContinueOnError)
rflag.BoolVar(&interactive, "i", false, "start an interactive REPL")
rflag.BoolVar(&useSyscall, "syscall", useSyscall, "include syscall symbols")
rflag.BoolVar(&useUnrestricted, "unrestricted", useUnrestricted, "include unrestricted symbols")
rflag.StringVar(&tags, "tags", "", "set a list of build tags")
rflag.BoolVar(&useUnsafe, "unsafe", useUnsafe, "include unsafe symbols")
rflag.BoolVar(&noAutoImport, "noautoimport", false, "do not auto import pre-compiled packages. Import names that would result in collisions (e.g. rand from crypto/rand and rand from math/rand) are automatically renamed (crypto_rand and math_rand)")
rflag.StringVar(&cmd, "e", "", "set the command to be executed (instead of script or/and shell)")
rflag.Usage = func() {
fmt.Println("Usage: yaegi run [options] [path] [args]")
fmt.Println("Options:")
rflag.PrintDefaults()
}
if err = rflag.Parse(arg); err != nil {
return err
}
args := rflag.Args()
i := interp.New(interp.Options{GoPath: build.Default.GOPATH, BuildTags: strings.Split(tags, ",")})
if err := i.Use(stdlib.Symbols); err != nil {
return err
}
if err := i.Use(interp.Symbols); err != nil {
return err
}
if useSyscall {
if err := i.Use(syscall.Symbols); err != nil {
return err
}
// Using a environment var allows a nested interpreter to import the syscall package.
if err := os.Setenv("YAEGI_SYSCALL", "1"); err != nil {
return err
}
}
if useUnsafe {
if err := i.Use(unsafe.Symbols); err != nil {
return err
}
if err := os.Setenv("YAEGI_UNSAFE", "1"); err != nil {
return err
}
}
if useUnrestricted {
// Use of unrestricted symbols should always follow stdlib and syscall symbols, to update them.
if err := i.Use(unrestricted.Symbols); err != nil {
return err
}
if err := os.Setenv("YAEGI_UNRESTRICTED", "1"); err != nil {
return err
}
}
if cmd != "" {
if !noAutoImport {
i.ImportUsed()
}
var v reflect.Value
v, err = i.Eval(cmd)
if len(args) == 0 && v.IsValid() {
fmt.Println(v)
}
}
if len(args) == 0 {
if cmd == "" || interactive {
showError(err)
if !noAutoImport {
i.ImportUsed()
}
_, err = i.REPL()
}
return err
}
// Skip first os arg to set command line as expected by interpreted main.
path := args[0]
os.Args = arg
flag.CommandLine = flag.NewFlagSet(path, flag.ExitOnError)
if isFile(path) {
err = runFile(i, path, noAutoImport)
} else {
_, err = i.EvalPath(path)
}
if err != nil {
return err
}
if interactive {
_, err = i.REPL()
}
return err
}
func isFile(path string) bool {
fi, err := os.Stat(path)
return err == nil && fi.Mode().IsRegular()
}
func runFile(i *interp.Interpreter, path string, noAutoImport bool) error {
b, err := ioutil.ReadFile(path)
if err != nil {
return err
}
if s := string(b); strings.HasPrefix(s, "#!") {
// Allow executable go scripts, Have the same behavior as in interactive mode.
s = strings.Replace(s, "#!", "//", 1)
if !noAutoImport {
i.ImportUsed()
}
_, err = i.Eval(s)
return err
}
// Files not starting with "#!" are supposed to be pure Go, directly Evaled.
_, err = i.EvalPath(path)
return err
}
func showError(err error) {
if err == nil {
return
}
fmt.Fprintln(os.Stderr, err)
if p, ok := err.(interp.Panic); ok {
fmt.Fprintln(os.Stderr, string(p.Stack))
}
}
yaegi-0.10.0/cmd/yaegi/test.go 0000664 0000000 0000000 00000011336 14120400617 0016034 0 ustar 00root root 0000000 0000000 package main
import (
"errors"
"flag"
"fmt"
"go/build"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"testing"
"github.com/traefik/yaegi/interp"
"github.com/traefik/yaegi/stdlib"
"github.com/traefik/yaegi/stdlib/syscall"
"github.com/traefik/yaegi/stdlib/unrestricted"
"github.com/traefik/yaegi/stdlib/unsafe"
)
func test(arg []string) (err error) {
var (
bench string
benchmem bool
benchtime string
count string
cpu string
failfast bool
run string
short bool
tags string
timeout string
verbose bool
)
// The following flags are initialized from environment.
useSyscall, _ := strconv.ParseBool(os.Getenv("YAEGI_SYSCALL"))
useUnrestricted, _ := strconv.ParseBool(os.Getenv("YAEGI_UNRESTRICTED"))
useUnsafe, _ := strconv.ParseBool(os.Getenv("YAEGI_UNSAFE"))
tflag := flag.NewFlagSet("test", flag.ContinueOnError)
tflag.StringVar(&bench, "bench", "", "Run only those benchmarks matching a regular expression.")
tflag.BoolVar(&benchmem, "benchmem", false, "Print memory allocation statistics for benchmarks.")
tflag.StringVar(&benchtime, "benchtime", "", "Run enough iterations of each benchmark to take t.")
tflag.StringVar(&count, "count", "", "Run each test and benchmark n times (default 1).")
tflag.StringVar(&cpu, "cpu", "", "Specify a list of GOMAXPROCS values for which the tests or benchmarks should be executed.")
tflag.BoolVar(&failfast, "failfast", false, "Do not start new tests after the first test failure.")
tflag.StringVar(&run, "run", "", "Run only those tests matching a regular expression.")
tflag.BoolVar(&short, "short", false, "Tell long-running tests to shorten their run time.")
tflag.StringVar(&tags, "tags", "", "Set a list of build tags.")
tflag.StringVar(&timeout, "timeout", "", "If a test binary runs longer than duration d, panic.")
tflag.BoolVar(&useUnrestricted, "unrestricted", useUnrestricted, "Include unrestricted symbols.")
tflag.BoolVar(&useUnsafe, "unsafe", useUnsafe, "Include usafe symbols.")
tflag.BoolVar(&useSyscall, "syscall", useSyscall, "Include syscall symbols.")
tflag.BoolVar(&verbose, "v", false, "Verbose output: log all tests as they are run.")
tflag.Usage = func() {
fmt.Println("Usage: yaegi test [options] [path]")
fmt.Println("Options:")
tflag.PrintDefaults()
}
if err = tflag.Parse(arg); err != nil {
return err
}
args := tflag.Args()
path := "."
if len(args) > 0 {
path = args[0]
}
// Overwrite os.Args with correct flags to setup testing.Init.
tf := []string{""}
if bench != "" {
tf = append(tf, "-test.bench", bench)
}
if benchmem {
tf = append(tf, "-test.benchmem")
}
if benchtime != "" {
tf = append(tf, "-test.benchtime", benchtime)
}
if count != "" {
tf = append(tf, "-test.count", count)
}
if cpu != "" {
tf = append(tf, "-test.cpu", cpu)
}
if failfast {
tf = append(tf, "-test.failfast")
}
if run != "" {
tf = append(tf, "-test.run", run)
}
if short {
tf = append(tf, "-test.short")
}
if timeout != "" {
tf = append(tf, "-test.timeout", timeout)
}
if verbose {
tf = append(tf, "-test.v")
}
testing.Init()
os.Args = tf
flag.Parse()
path += string(filepath.Separator)
var dir string
switch strings.Split(path, string(filepath.Separator))[0] {
case ".", "..", string(filepath.Separator):
dir = path
default:
dir = filepath.Join(build.Default.GOPATH, "src", path)
}
if err = os.Chdir(dir); err != nil {
return err
}
i := interp.New(interp.Options{GoPath: build.Default.GOPATH, BuildTags: strings.Split(tags, ",")})
if err := i.Use(stdlib.Symbols); err != nil {
return err
}
if err := i.Use(interp.Symbols); err != nil {
return err
}
if useSyscall {
if err := i.Use(syscall.Symbols); err != nil {
return err
}
// Using a environment var allows a nested interpreter to import the syscall package.
if err := os.Setenv("YAEGI_SYSCALL", "1"); err != nil {
return err
}
}
if useUnrestricted {
if err := i.Use(unrestricted.Symbols); err != nil {
return err
}
if err := os.Setenv("YAEGI_UNRESTRICTED", "1"); err != nil {
return err
}
}
if useUnsafe {
if err := i.Use(unsafe.Symbols); err != nil {
return err
}
if err := os.Setenv("YAEGI_UNSAFE", "1"); err != nil {
return err
}
}
if err = i.EvalTest(path); err != nil {
return err
}
benchmarks := []testing.InternalBenchmark{}
tests := []testing.InternalTest{}
syms, ok := i.Symbols(path)[path]
if !ok {
return errors.New("No tests found")
}
for name, sym := range syms {
switch fun := sym.Interface().(type) {
case func(*testing.B):
benchmarks = append(benchmarks, testing.InternalBenchmark{name, fun})
case func(*testing.T):
tests = append(tests, testing.InternalTest{name, fun})
}
}
testing.Main(regexp.MatchString, tests, benchmarks, nil)
return nil
}
yaegi-0.10.0/cmd/yaegi/yaegi.go 0000664 0000000 0000000 00000010502 14120400617 0016145 0 ustar 00root root 0000000 0000000 /*
Yaegi interprets Go programs.
Yaegi reads Go language programs from standard input, string
parameters or files and run them.
If invoked with no arguments, it processes the standard input in
a Read-Eval-Print-Loop. A prompt is displayed if standard input is
a terminal.
File Mode
In file mode, as in a standard Go compiler, source files are read entirely
before being parsed, then evaluated. It allows to handle forward
declarations and to have package code split in multiple source files.
Go specifications fully apply in this mode.
All files are interpreted in file mode except the initial file if it
starts with "#!" characters (the shebang pattern to allow executable
scripts), for example "#!/usr/bin/env yaegi". In that case, the initial
file is interpreted in REPL mode.
REPL mode
In REPL mode, the interpreter parses the code incrementally. As soon
as a statement is complete, it evaluates it. This makes the interpreter
suitable for interactive command line and scripts.
Go specifications apply with the following differences:
All local and global declarations (const, var, type, func) are allowed,
including in short form, except that all identifiers must be defined
before use (as declarations inside a standard Go function).
The statements are evaluated in the global space, within an implicit
"main" package.
It is not necessary to have a package statement, or a main function in
REPL mode. Import statements for preloaded binary packages can also
be avoided (i.e. all the standard library except the few packages
where default names collide, as "math/rand" and "crypto/rand", for which
an explicit import is still necessary).
Note that the source packages are always interpreted in file mode,
even if imported from REPL.
The following extract is a valid executable script:
#!/usr/bin/env yaegi
helloHandler := func(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "Hello, world!\n")
}
http.HandleFunc("/hello", helloHandler)
log.Fatal(http.ListenAndServe(":8080", nil))
Example of a one liner:
$ yaegi -e 'println(reflect.TypeOf(fmt.Print))'
Options:
-e string
evaluate the string and return.
-i
start an interactive REPL after file execution.
-syscall
include syscall symbols.
-tags tag,list
a comma-separated list of build tags to consider satisfied during
the interpretation.
-unsafe
include unsafe symbols.
Environment variables:
YAEGI_SYSCALL=1
Include syscall symbols (same as -syscall flag).
YAEGI_UNRESTRICTED=1
Include unrestricted symbols (same as -unrestricted flag).
YAEGI_UNSAFE=1
Include unsafe symbols (same as -unsafe flag).
YAEGI_PROMPT=1
Force enable the printing of the REPL prompt and the result of last instruction,
even if stdin is not a terminal.
YAEGI_AST_DOT=1
Generate and display graphviz dot of AST with dotty(1)
YAEGI_CFG_DOT=1
Generate and display graphviz dot of CFG with dotty(1)
YAEGI_DOT_CMD='dot -Tsvg -ofoo.svg'
Defines how to process the dot code generated whenever YAEGI_AST_DOT and/or
YAEGI_CFG_DOT is enabled. If any of YAEGI_AST_DOT or YAEGI_CFG_DOT is set,
but YAEGI_DOT_CMD is not defined, the default is to write to a .dot file
next to the Go source file.
*/
package main
import (
"errors"
"flag"
"fmt"
"log"
"os"
"github.com/traefik/yaegi/interp"
)
const (
Extract = "extract"
Help = "help"
Run = "run"
Test = "test"
Version = "version"
)
var version = "devel" // This may be overwritten at build time.
func main() {
var cmd string
var err error
var exitCode int
log.SetFlags(log.Lshortfile) // Ease debugging.
if len(os.Args) > 1 {
cmd = os.Args[1]
}
switch cmd {
case Extract:
err = extractCmd(os.Args[2:])
case Help, "-h", "--help":
err = help(os.Args[2:])
case Run:
err = run(os.Args[2:])
case Test:
err = test(os.Args[2:])
case Version:
fmt.Println(version)
default:
// If no command is given, fallback to default "run" command.
// This allows scripts starting with "#!/usr/bin/env yaegi",
// as passing more than 1 argument to #! executable may be not supported
// on all platforms.
cmd = Run
err = run(os.Args[1:])
}
if err != nil && !errors.Is(err, flag.ErrHelp) {
fmt.Fprintln(os.Stderr, fmt.Errorf("%s: %w", cmd, err))
if p, ok := err.(interp.Panic); ok {
fmt.Fprintln(os.Stderr, string(p.Stack))
}
exitCode = 1
}
os.Exit(exitCode)
}
yaegi-0.10.0/cmd/yaegi/yaegi_test.go 0000664 0000000 0000000 00000006111 14120400617 0017205 0 ustar 00root root 0000000 0000000 package main
import (
"bytes"
"context"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
"time"
)
const (
// CITimeoutMultiplier is the multiplier for all timeouts in the CI.
CITimeoutMultiplier = 3
)
// Sleep pauses the current goroutine for at least the duration d.
func Sleep(d time.Duration) {
d = applyCIMultiplier(d)
time.Sleep(d)
}
func applyCIMultiplier(timeout time.Duration) time.Duration {
ci := os.Getenv("CI")
if ci == "" {
return timeout
}
b, err := strconv.ParseBool(ci)
if err != nil || !b {
return timeout
}
return time.Duration(float64(timeout) * CITimeoutMultiplier)
}
func TestYaegiCmdCancel(t *testing.T) {
tmp, err := ioutil.TempDir("", "yaegi-")
if err != nil {
t.Fatalf("failed to create tmp directory: %v", err)
}
defer func() {
err = os.RemoveAll(tmp)
if err != nil {
t.Errorf("failed to clean up %v: %v", tmp, err)
}
}()
yaegi := filepath.Join(tmp, "yaegi")
args := []string{"build"}
if raceDetectorSupported(runtime.GOOS, runtime.GOARCH) {
args = append(args, "-race")
}
args = append(args, "-o", yaegi, ".")
build := exec.Command("go", args...)
out, err := build.CombinedOutput()
if err != nil {
t.Fatalf("failed to build yaegi command: %v: %s", err, out)
}
// Test src must be terminated by a single newline.
tests := []string{
"for {}\n",
"select {}\n",
}
for _, src := range tests {
cmd := exec.Command(yaegi)
in, err := cmd.StdinPipe()
if err != nil {
t.Errorf("failed to get stdin pipe to yaegi command: %v", err)
}
var outBuf, errBuf bytes.Buffer
cmd.Stdout = &outBuf
cmd.Stderr = &errBuf
// https://golang.org/doc/articles/race_detector.html#Options
cmd.Env = []string{`GORACE="halt_on_error=1"`}
err = cmd.Start()
if err != nil {
t.Fatalf("failed to start yaegi command: %v", err)
}
_, err = in.Write([]byte(src))
if err != nil {
t.Errorf("failed pipe test source to yaegi command: %v", err)
}
Sleep(500 * time.Millisecond)
err = cmd.Process.Signal(os.Interrupt)
if err != nil {
t.Errorf("failed to send os.Interrupt to yaegi command: %v", err)
}
_, err = in.Write([]byte("1+1\n"))
if err != nil {
t.Errorf("failed to probe race: %v", err)
}
err = in.Close()
if err != nil {
t.Errorf("failed to close stdin pipe: %v", err)
}
err = cmd.Wait()
if err != nil {
if cmd.ProcessState.ExitCode() == 66 { // See race_detector.html article.
t.Errorf("race detected running yaegi command canceling %q: %v", src, err)
if testing.Verbose() {
t.Log(&errBuf)
}
} else {
t.Errorf("error running yaegi command for %q: %v", src, err)
}
continue
}
if strings.TrimSuffix(errBuf.String(), "\n") != context.Canceled.Error() {
t.Errorf("unexpected error: %q", &errBuf)
}
}
}
func raceDetectorSupported(goos, goarch string) bool {
switch goos {
case "linux":
return goarch == "amd64" || goarch == "ppc64le" || goarch == "arm64"
case "darwin":
return goarch == "amd64" || goarch == "arm64"
case "freebsd", "netbsd", "openbsd", "windows":
return goarch == "amd64"
default:
return false
}
}
yaegi-0.10.0/doc/ 0000775 0000000 0000000 00000000000 14120400617 0013426 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/doc/images/ 0000775 0000000 0000000 00000000000 14120400617 0014673 5 ustar 00root root 0000000 0000000 yaegi-0.10.0/doc/images/yaegi.png 0000664 0000000 0000000 00000273222 14120400617 0016507 0 ustar 00root root 0000000 0000000 PNG
IHDR _ bKGD IDATxy|T?sLada',"(n[WKMʚsm+KժݶKk(*
Y,laMfgy~$Ldy^4{0Ϝ B!B!B!B!B!B!B!B!B!B!B!B!B!B!B!B!B!B!B!B!B!B!B!B!2t eS>VaGKUuisTF«MO
r>S[mRdhF$H)&{ywkhU_-ZpTG!olz BdR!