Skip to content

Commit ec243ec

Browse files
committed
Add Result in examples
1 parent 52471a1 commit ec243ec

File tree

11 files changed

+151
-17
lines changed

11 files changed

+151
-17
lines changed

examples/basic/variables/function_returns_address_of_local_variable/function_returns_address_of_local_variable.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ func FunctionReturnsAddressOfLocalVariable() error {
3131
output.Stdoutf("[i1/i2]", "%v\t%v\n", *i1, *i2)
3232

3333
return nil
34+
35+
/*
36+
$ task
37+
task: [build] go build .
38+
task: [run] ./try-golang -onetime
39+
40+
ENTER EXAMPLE NAME: function_returns_address_of_local_variable
41+
42+
[Name] "function_returns_address_of_local_variable"
43+
[i1] 0xc0001a2908 1
44+
[i2] 0xc0001a2920 1
45+
[i1/i2] 2 2
46+
47+
48+
[Elapsed] 32.3µs
49+
*/
50+
3451
}
3552

3653
func f() *int {

examples/basic/variables/loopiterator/passing_a_loop_variable_to_goroutine_by_pointer.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ func PassingLoopVariableToGoroutineByPointer() error {
3838
goodpattern()
3939

4040
return nil
41+
42+
/*
43+
$ task
44+
task: [build] go build .
45+
task: [run] ./try-golang -onetime
46+
47+
ENTER EXAMPLE NAME: passing_loop_variable_to_goroutine_by_pointer
48+
49+
[Name] "passing_loop_variable_to_goroutine_by_pointer"
50+
[bad][v] addr=0xc000014958, value={1}
51+
[bad][v] addr=0xc000014970, value={2}
52+
[bad][v] addr=0xc000014978, value={3}
53+
[bad][v][goroutine] addr=0xc000014978, value={3}
54+
[bad][v][goroutine] addr=0xc000014970, value={2}
55+
[bad][v][goroutine] addr=0xc000014958, value={1}
56+
--------------------------------------------------
57+
[good][v] addr=0xc000202008, value={1}
58+
[good][v] addr=0xc000202028, value={2}
59+
[good][v] addr=0xc000202038, value={3}
60+
[good][v][goroutine] addr=0xc000202040, value={3}
61+
[good][v][goroutine] addr=0xc000202020, value={1}
62+
[good][v][goroutine] addr=0xc000202030, value={2}
63+
64+
65+
[Elapsed] 274.61µs
66+
*/
67+
4168
}
4269

4370
func badpattern() {

examples/basic/variables/loopiterator/using_reference_to_loop_iterator_variable.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,31 @@ func CommonMistakePattern() error {
3030
good()
3131

3232
return nil
33+
34+
/*
35+
$ task
36+
task: [build] go build .
37+
task: [run] ./try-golang -onetime
38+
39+
ENTER EXAMPLE NAME: using_ref_to_loop_iterator_variable
40+
41+
[Name] "using_ref_to_loop_iterator_variable"
42+
0 p=0xc0001a2908 v=0
43+
1 p=0xc0001a2910 v=1
44+
2 p=0xc0001a2918 v=2
45+
3 p=0xc0001a2920 v=3
46+
4 p=0xc0001a2928 v=4
47+
--------------------------------------------------
48+
0 p=0xc0001a2938 v=0
49+
1 p=0xc0001a2940 v=1
50+
2 p=0xc0001a2948 v=2
51+
3 p=0xc0001a2950 v=3
52+
4 p=0xc0001a2958 v=4
53+
54+
55+
[Elapsed] 57.61µs
56+
*/
57+
3358
}
3459

3560
func bad() {

examples/basic/variables/packagescope/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
このディレクトリには以下のサンプルがあります。
44

5-
| file | example name | note |
6-
|-----------------------------|--------------------------|--------------------|
7-
| package\_scope\_variable.go | package\_scope\_variable | パッケージ スコープな変数のサンプル |
8-
5+
| file | example name | note |
6+
| ------------------------- | ---------------------- | ----------------------------------- |
7+
| package_scope_variable.go | package_scope_variable | パッケージ スコープな変数のサンプル |

examples/basic/variables/packagescope/package_scope_variable.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,20 @@ func Basic() error {
1717
fmt.Printf("%#v\n%#v\n", pkgScopeVal1, PkgScopeVal1)
1818

1919
return nil
20+
21+
/*
22+
$ task
23+
task: [build] go build .
24+
task: [run] ./try-golang -onetime
25+
26+
ENTER EXAMPLE NAME: package_scope_variable
27+
28+
[Name] "package_scope_variable"
29+
"private package scope variable"
30+
"public package scope variable"
31+
32+
33+
[Elapsed] 4.52µs
34+
*/
35+
2036
}

examples/basic/variables/shadowing/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
このディレクトリには以下のサンプルがあります。
44

5-
| file | example name | note |
6-
|------------------------|---------------------|--------------------------|
7-
| shadowing\_variable.go | shadowing\_variable | 変数のshadowingについてのサンプルです。 |
8-
5+
| file | example name | note |
6+
| --------------------- | ------------------ | --------------------------------------- |
7+
| shadowing_variable.go | shadowing_variable | 変数のshadowingについてのサンプルです。 |

examples/basic/variables/shadowing/shadowing_variable.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@ func Basic() error {
2626
noShadowing()
2727

2828
return nil
29+
30+
/*
31+
$ task
32+
task: [build] go build .
33+
task: [run] ./try-golang -onetime
34+
35+
ENTER EXAMPLE NAME: shadowing_variable
36+
37+
[Name] "shadowing_variable"
38+
[shadowing ] --------------------------------------
39+
CHECKPOINT: word(0xc000118f10)
40+
RESULT : nil
41+
[no shadowing] --------------------------------------
42+
CHECKPOINT: word(0xc000118f60)
43+
RESULT : word(0xc000118f60)
44+
45+
46+
[Elapsed] 38.58µs
47+
*/
48+
2949
}
3050

3151
func do(v string) (*string, error) {

examples/basic/variables/shortassignment/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
このディレクトリには以下のサンプルがあります。
44

5-
| file | example name | note |
6-
|---------------------------------|------------------------------|------------------------------|
7-
| short\_assignment\_statement.go | short\_assignment\_statement | ":=" を使用した簡易変数初期化方法についてのサンプル |
8-
5+
| file | example name | note |
6+
| ----------------------------- | -------------------------- | --------------------------------------------------- |
7+
| short_assignment_statement.go | short_assignment_statement | ":=" を使用した簡易変数初期化方法についてのサンプル |

examples/basic/variables/shortassignment/short_assignment_statement.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func Basic() error {
1616
return err
1717
}
1818

19-
f := filepath.Join(dir, "basic", "variables", "short_assignment_statement.go")
19+
f := filepath.Join(dir, "examples", "basic", "variables", "shortassignment", "short_assignment_statement.go")
2020

2121
finfo, err := os.Stat(f)
2222
if err != nil {
@@ -26,4 +26,21 @@ func Basic() error {
2626
fmt.Printf("現在の作業ディレクトリ: %s\nファイルパス: %s\nサイズ: %d bytes\n", dir, f, finfo.Size())
2727

2828
return nil
29+
30+
/*
31+
$ task
32+
task: [build] go build .
33+
task: [run] ./try-golang -onetime
34+
35+
ENTER EXAMPLE NAME: short_assignment_statement
36+
37+
[Name] "short_assignment_statement"
38+
現在の作業ディレクトリ: /workspace/try-golang
39+
ファイルパス: /workspace/try-golang/examples/basic/variables/shortassignment/short_assignment_statement.go
40+
サイズ: 890 bytes
41+
42+
43+
[Elapsed] 83.41µs
44+
*/
45+
2946
}

examples/basic/variables/varstatement/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
このディレクトリには以下のサンプルがあります。
44

5-
| file | example name | note |
6-
|----------------------------|-------------------------|-------------------------|
7-
| var\_statement\_declare.go | var\_statement\_declare | var による 変数 の宣言についてのサンプル |
8-
5+
| file | example name | note |
6+
| ------------------------ | --------------------- | ---------------------------------------- |
7+
| var_statement_declare.go | var_statement_declare | var による 変数 の宣言についてのサンプル |

0 commit comments

Comments
 (0)