當前位置: 首頁>>代碼示例>>Golang>>正文


Golang influxql.NewScanner函數代碼示例

本文整理匯總了Golang中github.com/influxdb/influxdb/influxql.NewScanner函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewScanner函數的具體用法?Golang NewScanner怎麽用?Golang NewScanner使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewScanner函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestScanRegex

// Test scanning regex
func TestScanRegex(t *testing.T) {
	var tests = []struct {
		in  string
		tok influxql.Token
		lit string
		err string
	}{
		{in: `/^payments\./`, tok: influxql.REGEX, lit: `^payments\.`},
		{in: `/foo\/bar/`, tok: influxql.REGEX, lit: `foo/bar`},
		{in: `/foo\\/bar/`, tok: influxql.REGEX, lit: `foo\/bar`},
		{in: `/foo\\bar/`, tok: influxql.REGEX, lit: `foo\\bar`},
		{in: `/http\:\/\/www\.example\.com/`, tok: influxql.REGEX, lit: `http\://www\.example\.com`},
	}

	for i, tt := range tests {
		s := influxql.NewScanner(strings.NewReader(tt.in))
		tok, _, lit := s.ScanRegex()
		if tok != tt.tok {
			t.Errorf("%d. %s: error:\n\texp=%s\n\tgot=%s\n", i, tt.in, tt.tok.String(), tok.String())
		}
		if lit != tt.lit {
			t.Errorf("%d. %s: error:\n\texp=%s\n\tgot=%s\n", i, tt.in, tt.lit, lit)
		}
	}
}
開發者ID:nrshrivatsan,項目名稱:influxdb,代碼行數:26,代碼來源:scanner_test.go

示例2: TestScanner_Scan_Multi

// Ensure the scanner can scan a series of tokens correctly.
func TestScanner_Scan_Multi(t *testing.T) {
	type result struct {
		tok influxql.Token
		pos influxql.Pos
		lit string
	}
	exp := []result{
		{tok: influxql.SELECT, pos: influxql.Pos{Line: 0, Char: 0}, lit: ""},
		{tok: influxql.WS, pos: influxql.Pos{Line: 0, Char: 6}, lit: " "},
		{tok: influxql.IDENT, pos: influxql.Pos{Line: 0, Char: 7}, lit: "value"},
		{tok: influxql.WS, pos: influxql.Pos{Line: 0, Char: 12}, lit: " "},
		{tok: influxql.FROM, pos: influxql.Pos{Line: 0, Char: 13}, lit: ""},
		{tok: influxql.WS, pos: influxql.Pos{Line: 0, Char: 17}, lit: " "},
		{tok: influxql.IDENT, pos: influxql.Pos{Line: 0, Char: 18}, lit: "myseries"},
		{tok: influxql.WS, pos: influxql.Pos{Line: 0, Char: 26}, lit: " "},
		{tok: influxql.WHERE, pos: influxql.Pos{Line: 0, Char: 27}, lit: ""},
		{tok: influxql.WS, pos: influxql.Pos{Line: 0, Char: 32}, lit: " "},
		{tok: influxql.IDENT, pos: influxql.Pos{Line: 0, Char: 33}, lit: "a"},
		{tok: influxql.WS, pos: influxql.Pos{Line: 0, Char: 34}, lit: " "},
		{tok: influxql.EQ, pos: influxql.Pos{Line: 0, Char: 35}, lit: ""},
		{tok: influxql.WS, pos: influxql.Pos{Line: 0, Char: 36}, lit: " "},
		{tok: influxql.STRING, pos: influxql.Pos{Line: 0, Char: 36}, lit: "b"},
		{tok: influxql.EOF, pos: influxql.Pos{Line: 0, Char: 40}, lit: ""},
	}

	// Create a scanner.
	v := `SELECT value from myseries WHERE a = 'b'`
	s := influxql.NewScanner(strings.NewReader(v))

	// Continually scan until we reach the end.
	var act []result
	for {
		tok, pos, lit := s.Scan()
		act = append(act, result{tok, pos, lit})
		if tok == influxql.EOF {
			break
		}
	}

	// Verify the token counts match.
	if len(exp) != len(act) {
		t.Fatalf("token count mismatch: exp=%d, got=%d", len(exp), len(act))
	}

	// Verify each token matches.
	for i := range exp {
		if !reflect.DeepEqual(exp[i], act[i]) {
			t.Fatalf("%d. token mismatch:\n\nexp=%#v\n\ngot=%#v", i, exp[i], act[i])
		}
	}
}
開發者ID:nrshrivatsan,項目名稱:influxdb,代碼行數:52,代碼來源:scanner_test.go

示例3: TestScanner_Scan


//.........這裏部分代碼省略.........
		{s: `100`, tok: influxql.NUMBER, lit: `100`},
		{s: `100.23`, tok: influxql.NUMBER, lit: `100.23`},
		{s: `+100.23`, tok: influxql.NUMBER, lit: `+100.23`},
		{s: `-100.23`, tok: influxql.NUMBER, lit: `-100.23`},
		{s: `-100.`, tok: influxql.NUMBER, lit: `-100`},
		{s: `.23`, tok: influxql.NUMBER, lit: `.23`},
		{s: `+.23`, tok: influxql.NUMBER, lit: `+.23`},
		{s: `-.23`, tok: influxql.NUMBER, lit: `-.23`},
		//{s: `.`, tok: influxql.ILLEGAL, lit: `.`},
		{s: `-.`, tok: influxql.SUB, lit: ``},
		{s: `+.`, tok: influxql.ADD, lit: ``},
		{s: `10.3s`, tok: influxql.NUMBER, lit: `10.3`},

		// Durations
		{s: `10u`, tok: influxql.DURATION_VAL, lit: `10u`},
		{s: `10µ`, tok: influxql.DURATION_VAL, lit: `10µ`},
		{s: `10ms`, tok: influxql.DURATION_VAL, lit: `10ms`},
		{s: `-1s`, tok: influxql.DURATION_VAL, lit: `-1s`},
		{s: `10m`, tok: influxql.DURATION_VAL, lit: `10m`},
		{s: `10h`, tok: influxql.DURATION_VAL, lit: `10h`},
		{s: `10d`, tok: influxql.DURATION_VAL, lit: `10d`},
		{s: `10w`, tok: influxql.DURATION_VAL, lit: `10w`},
		{s: `10x`, tok: influxql.NUMBER, lit: `10`}, // non-duration unit

		// Keywords
		{s: `ALL`, tok: influxql.ALL},
		{s: `ALTER`, tok: influxql.ALTER},
		{s: `AS`, tok: influxql.AS},
		{s: `ASC`, tok: influxql.ASC},
		{s: `BEGIN`, tok: influxql.BEGIN},
		{s: `BY`, tok: influxql.BY},
		{s: `CREATE`, tok: influxql.CREATE},
		{s: `CONTINUOUS`, tok: influxql.CONTINUOUS},
		{s: `DATABASE`, tok: influxql.DATABASE},
		{s: `DATABASES`, tok: influxql.DATABASES},
		{s: `DEFAULT`, tok: influxql.DEFAULT},
		{s: `DELETE`, tok: influxql.DELETE},
		{s: `DESC`, tok: influxql.DESC},
		{s: `DROP`, tok: influxql.DROP},
		{s: `DURATION`, tok: influxql.DURATION},
		{s: `END`, tok: influxql.END},
		{s: `EXISTS`, tok: influxql.EXISTS},
		{s: `EXPLAIN`, tok: influxql.EXPLAIN},
		{s: `FIELD`, tok: influxql.FIELD},
		{s: `FROM`, tok: influxql.FROM},
		{s: `GRANT`, tok: influxql.GRANT},
		{s: `GROUP`, tok: influxql.GROUP},
		{s: `IF`, tok: influxql.IF},
		{s: `INNER`, tok: influxql.INNER},
		{s: `INSERT`, tok: influxql.INSERT},
		{s: `INTO`, tok: influxql.INTO},
		{s: `KEY`, tok: influxql.KEY},
		{s: `KEYS`, tok: influxql.KEYS},
		{s: `LIMIT`, tok: influxql.LIMIT},
		{s: `SHOW`, tok: influxql.SHOW},
		{s: `SHARDS`, tok: influxql.SHARDS},
		{s: `MEASUREMENT`, tok: influxql.MEASUREMENT},
		{s: `MEASUREMENTS`, tok: influxql.MEASUREMENTS},
		{s: `NOT`, tok: influxql.NOT},
		{s: `OFFSET`, tok: influxql.OFFSET},
		{s: `ON`, tok: influxql.ON},
		{s: `ORDER`, tok: influxql.ORDER},
		{s: `PASSWORD`, tok: influxql.PASSWORD},
		{s: `POLICY`, tok: influxql.POLICY},
		{s: `POLICIES`, tok: influxql.POLICIES},
		{s: `PRIVILEGES`, tok: influxql.PRIVILEGES},
		{s: `QUERIES`, tok: influxql.QUERIES},
		{s: `QUERY`, tok: influxql.QUERY},
		{s: `READ`, tok: influxql.READ},
		{s: `RENAME`, tok: influxql.RENAME},
		{s: `RETENTION`, tok: influxql.RETENTION},
		{s: `REVOKE`, tok: influxql.REVOKE},
		{s: `SELECT`, tok: influxql.SELECT},
		{s: `SERIES`, tok: influxql.SERIES},
		{s: `SERVER`, tok: influxql.SERVER},
		{s: `SERVERS`, tok: influxql.SERVERS},
		{s: `TAG`, tok: influxql.TAG},
		{s: `TO`, tok: influxql.TO},
		{s: `USER`, tok: influxql.USER},
		{s: `USERS`, tok: influxql.USERS},
		{s: `VALUES`, tok: influxql.VALUES},
		{s: `WHERE`, tok: influxql.WHERE},
		{s: `WITH`, tok: influxql.WITH},
		{s: `WRITE`, tok: influxql.WRITE},
		{s: `explain`, tok: influxql.EXPLAIN}, // case insensitive
		{s: `seLECT`, tok: influxql.SELECT},   // case insensitive
	}

	for i, tt := range tests {
		s := influxql.NewScanner(strings.NewReader(tt.s))
		tok, pos, lit := s.Scan()
		if tt.tok != tok {
			t.Errorf("%d. %q token mismatch: exp=%q got=%q <%q>", i, tt.s, tt.tok, tok, lit)
		} else if tt.pos.Line != pos.Line || tt.pos.Char != pos.Char {
			t.Errorf("%d. %q pos mismatch: exp=%#v got=%#v", i, tt.s, tt.pos, pos)
		} else if tt.lit != lit {
			t.Errorf("%d. %q literal mismatch: exp=%q got=%q", i, tt.s, tt.lit, lit)
		}
	}
}
開發者ID:nrshrivatsan,項目名稱:influxdb,代碼行數:101,代碼來源:scanner_test.go


注:本文中的github.com/influxdb/influxdb/influxql.NewScanner函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。