Ejemplo n.º 1
0
func main() {

	var seq <-chan string

	if *filename != "" {

		// file mode
		c, err := reader.OpenXLSXSheet(*filename, 0)
		if err != nil {
			panic(err)
			return
		}

		if *max == 0 {
			*max = c.Len() // last row
		}

		fmter := func(n int) (str string, err error) {
			strs, err := reader.ReadMulti(c, 0, 1)(n)
			if err != nil {
				return
			}
			str = strings.Join(strs, ", ")
			return
		}
		seq = formatNum(fmter, uniqueInt(randInts(*min-1, *max-1)))
	} else {
		// raw number mode
		l := len(fmt.Sprintf("%d", *max))
		seq = formatNum(padNumToStr(l), uniqueInt(randInts(*min, *max)))
	}

	url := "https://github.com/yookoala/lottery"
	fmt.Printf("\nSource code: %s\n\n", url)
	fmt.Printf("Max: %d\n", *max)
	fmt.Printf("Min: %d\n", *min)
	fmt.Printf("=================\n\n")

	reader := bufio.NewReader(os.Stdin)
	for n := range seq {
		t := time.Now().Format("15:04:05.999")
		t += strings.Repeat("0", 12-len(t))
		fmt.Printf("[%s] %s", t, n)
		reader.ReadString('\n')
	}
}
Ejemplo n.º 2
0
func TestXLSReader(t *testing.T) {
	f, err := reader.OpenXLSXSheet("./_test/test.xlsx", 0)
	if err != nil {
		t.Errorf("unable to open xlsx file: %#v", err.Error())
	}
	for i := 0; i < f.Len(); i++ {
		r, err := f.Row(i)
		if err != nil {
			t.Errorf("unable to open row: %#v", err.Error())
		}
		for j := 0; j < r.Len(); j++ {
			v := r.ReadString(j)
			if exp := testXLSXdata[i][j]; v != exp {
				t.Errorf("unexpected value at (%d, %d)\n"+
					"expected: %#v; got: %#v",
					i, j, exp, v)
			}
			t.Logf("value: %#v", v)
		}
	}
}
Ejemplo n.º 3
0
func TestXLSXReadMulti(t *testing.T) {

	f, err := reader.OpenXLSXSheet("./_test/test.xlsx", 0)
	if err != nil {
		t.Errorf("unable to open xlsx file: %#v", err.Error())
	}

	for i := 0; i < f.Len(); i++ {
		strs, err := reader.ReadMulti(f, 0, 1)(i)
		if err != nil {
			t.Errorf("unable to ReadMulti on line %d: %#v",
				i, err.Error())
		}

		res := strings.Join(strs, ", ")
		exp := testXLSXdata[i][0] + ", " + testXLSXdata[i][1]
		if res != exp {
			t.Errorf("row %d exptects %#v, got %#v",
				exp, res)
		}

		t.Logf("%#v", res)
	}
}
Ejemplo n.º 4
0
func TestXLSReader_nonsheet(t *testing.T) {
	_, err := reader.OpenXLSXSheet("./_test/test.xlsx", 12)
	if err == nil {
		t.Error("failed to trigger error reading non-exist page")
	}
}