package main

import (
	"encoding/json"
	"testing"
)

func Example_receivers() {
	receivers()
	// Output:
	// 1 [11]
	// 2
	// 2 3
}
func Example_methodFunctions() {
	methodFunctions()
	// Output:
	// 1 11
	// 12 12
	// func(main.Counter) int | func(*main.Counter)
}
func Example_embedding() {
	embedding()
	// Output:
	// service base base
	// 4 4
	// 6
}
func Example_tags() {
	tags()
	// Output:
	// {"name":"gopher"} <nil>
	// name required
	// "" true | "" false
}
func TestNilEmbeddedPointer(t *testing.T) {
	var p PointerEmbedded
	defer func() {
		if recover() == nil {
			t.Fatal("expected nil dereference")
		}
	}()
	p.Inc()
}
func TestTagDoesNotValidate(t *testing.T) {
	b, err := json.Marshal(User{})
	if err != nil || string(b) != `{"name":""}` {
		t.Fatalf("got %s, %v", b, err)
	}
}
func TestNamedComposition(t *testing.T) {
	type Holder struct{ Counter Counter }
	h := Holder{Counter: Counter{N: 2}}
	h.Counter.Inc()
	if h.Counter.Value() != 3 {
		t.Fatal("named field not updated")
	}
}
