Skip to content

Instantly share code, notes, and snippets.

@PichuChen
Created April 2, 2019 09:10
Show Gist options
  • Save PichuChen/e1929fb09f1848b60f061294cc97626a to your computer and use it in GitHub Desktop.
Save PichuChen/e1929fb09f1848b60f061294cc97626a to your computer and use it in GitHub Desktop.
package main
/*
Copyright 2019 Pichu Chen
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.
*/
import (
"testing"
"time"
)
func TestCnvert(t *testing.T) {
type E struct {
RegnalName string
Year int
Error error
}
cases := []struct {
Input string
Excepted E
}{
{
Input: "2036-05-01",
Excepted: E{
RegnalName: "令和",
Year: 18,
Error: nil,
},
},
}
for cN, c := range cases {
inputTime, _ := time.Parse("2006-01-02", c.Input)
actualRegnalName, actualYear, actualError := convert(inputTime)
if actualRegnalName != c.Excepted.RegnalName {
t.Errorf("Testcase %d: RegnalName not match want %s, got %s", cN, c.Excepted.RegnalName, actualRegnalName)
}
if actualYear != c.Excepted.Year {
t.Errorf("Testcase %d: Year not match want %d, got %d", cN, c.Excepted.Year, actualYear)
}
if actualError != c.Excepted.Error {
t.Errorf("Testcase %d: Error not match want %v, got %v", cN, c.Excepted.Error, actualError)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment