How to use add method of parser Package

Best Syzkaller code snippet using parser.add

math_parser.go

Source:math_parser.go Github

copy

Full Screen

1// Code generated from parser/Math.g4 by ANTLR 4.7.1. DO NOT EDIT.2package parser // Math3import (4 "fmt"5 "reflect"6 "strconv"7 "github.com/antlr/antlr4/runtime/Go/antlr"8)9// Suppress unused import errors10var _ = fmt.Printf11var _ = reflect.Copy12var _ = strconv.Itoa13var parserATN = []uint16{14 3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 11, 27, 4,15 2, 9, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 5, 2, 11, 10, 2, 3, 2, 3,16 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 7, 2, 22, 10, 2, 12, 2, 14,17 2, 25, 11, 2, 3, 2, 2, 3, 2, 3, 2, 2, 4, 3, 2, 5, 6, 3, 2, 3, 4, 2, 29,18 2, 10, 3, 2, 2, 2, 4, 5, 8, 2, 1, 2, 5, 6, 7, 9, 2, 2, 6, 7, 5, 2, 2, 2,19 7, 8, 7, 10, 2, 2, 8, 11, 3, 2, 2, 2, 9, 11, 7, 8, 2, 2, 10, 4, 3, 2, 2,20 2, 10, 9, 3, 2, 2, 2, 11, 23, 3, 2, 2, 2, 12, 13, 12, 6, 2, 2, 13, 14,21 7, 7, 2, 2, 14, 22, 5, 2, 2, 7, 15, 16, 12, 5, 2, 2, 16, 17, 9, 2, 2, 2,22 17, 22, 5, 2, 2, 6, 18, 19, 12, 4, 2, 2, 19, 20, 9, 3, 2, 2, 20, 22, 5,23 2, 2, 5, 21, 12, 3, 2, 2, 2, 21, 15, 3, 2, 2, 2, 21, 18, 3, 2, 2, 2, 22,24 25, 3, 2, 2, 2, 23, 21, 3, 2, 2, 2, 23, 24, 3, 2, 2, 2, 24, 3, 3, 2, 2,25 2, 25, 23, 3, 2, 2, 2, 5, 10, 21, 23,26}27var deserializer = antlr.NewATNDeserializer(nil)28var deserializedATN = deserializer.DeserializeFromUInt16(parserATN)29var literalNames = []string{30 "", "'+'", "'-'", "'*'", "'/'", "'^'", "", "'('", "')'",31}32var symbolicNames = []string{33 "", "ADD", "SUB", "MUL", "DIV", "POW", "ROMAN", "LPAREN", "RPAREN", "WS",34}35var ruleNames = []string{36 "expr",37}38var decisionToDFA = make([]*antlr.DFA, len(deserializedATN.DecisionToState))39func init() {40 for index, ds := range deserializedATN.DecisionToState {41 decisionToDFA[index] = antlr.NewDFA(ds, index)42 }43}44type MathParser struct {45 *antlr.BaseParser46}47func NewMathParser(input antlr.TokenStream) *MathParser {48 this := new(MathParser)49 this.BaseParser = antlr.NewBaseParser(input)50 this.Interpreter = antlr.NewParserATNSimulator(this, deserializedATN, decisionToDFA, antlr.NewPredictionContextCache())51 this.RuleNames = ruleNames52 this.LiteralNames = literalNames53 this.SymbolicNames = symbolicNames54 this.GrammarFileName = "Math.g4"55 return this56}57// MathParser tokens.58const (59 MathParserEOF = antlr.TokenEOF60 MathParserADD = 161 MathParserSUB = 262 MathParserMUL = 363 MathParserDIV = 464 MathParserPOW = 565 MathParserROMAN = 666 MathParserLPAREN = 767 MathParserRPAREN = 868 MathParserWS = 969)70// MathParserRULE_expr is the MathParser rule.71const MathParserRULE_expr = 072// IExprContext is an interface to support dynamic dispatch.73type IExprContext interface {74 antlr.ParserRuleContext75 // GetParser returns the parser.76 GetParser() antlr.Parser77 // IsExprContext differentiates from other interfaces.78 IsExprContext()79}80type ExprContext struct {81 *antlr.BaseParserRuleContext82 parser antlr.Parser83}84func NewEmptyExprContext() *ExprContext {85 var p = new(ExprContext)86 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)87 p.RuleIndex = MathParserRULE_expr88 return p89}90func (*ExprContext) IsExprContext() {}91func NewExprContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ExprContext {92 var p = new(ExprContext)93 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)94 p.parser = parser95 p.RuleIndex = MathParserRULE_expr96 return p97}98func (s *ExprContext) GetParser() antlr.Parser { return s.parser }99func (s *ExprContext) CopyFrom(ctx *ExprContext) {100 s.BaseParserRuleContext.CopyFrom(ctx.BaseParserRuleContext)101}102func (s *ExprContext) GetRuleContext() antlr.RuleContext {103 return s104}105func (s *ExprContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {106 return antlr.TreesStringTree(s, ruleNames, recog)107}108type OrderContext struct {109 *ExprContext110}111func NewOrderContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *OrderContext {112 var p = new(OrderContext)113 p.ExprContext = NewEmptyExprContext()114 p.parser = parser115 p.CopyFrom(ctx.(*ExprContext))116 return p117}118func (s *OrderContext) GetRuleContext() antlr.RuleContext {119 return s120}121func (s *OrderContext) AllExpr() []IExprContext {122 var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IExprContext)(nil)).Elem())123 var tst = make([]IExprContext, len(ts))124 for i, t := range ts {125 if t != nil {126 tst[i] = t.(IExprContext)127 }128 }129 return tst130}131func (s *OrderContext) Expr(i int) IExprContext {132 var t = s.GetTypedRuleContext(reflect.TypeOf((*IExprContext)(nil)).Elem(), i)133 if t == nil {134 return nil135 }136 return t.(IExprContext)137}138func (s *OrderContext) POW() antlr.TerminalNode {139 return s.GetToken(MathParserPOW, 0)140}141func (s *OrderContext) EnterRule(listener antlr.ParseTreeListener) {142 if listenerT, ok := listener.(MathListener); ok {143 listenerT.EnterOrder(s)144 }145}146func (s *OrderContext) ExitRule(listener antlr.ParseTreeListener) {147 if listenerT, ok := listener.(MathListener); ok {148 listenerT.ExitOrder(s)149 }150}151type BraceContext struct {152 *ExprContext153}154func NewBraceContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *BraceContext {155 var p = new(BraceContext)156 p.ExprContext = NewEmptyExprContext()157 p.parser = parser158 p.CopyFrom(ctx.(*ExprContext))159 return p160}161func (s *BraceContext) GetRuleContext() antlr.RuleContext {162 return s163}164func (s *BraceContext) LPAREN() antlr.TerminalNode {165 return s.GetToken(MathParserLPAREN, 0)166}167func (s *BraceContext) Expr() IExprContext {168 var t = s.GetTypedRuleContext(reflect.TypeOf((*IExprContext)(nil)).Elem(), 0)169 if t == nil {170 return nil171 }172 return t.(IExprContext)173}174func (s *BraceContext) RPAREN() antlr.TerminalNode {175 return s.GetToken(MathParserRPAREN, 0)176}177func (s *BraceContext) EnterRule(listener antlr.ParseTreeListener) {178 if listenerT, ok := listener.(MathListener); ok {179 listenerT.EnterBrace(s)180 }181}182func (s *BraceContext) ExitRule(listener antlr.ParseTreeListener) {183 if listenerT, ok := listener.(MathListener); ok {184 listenerT.ExitBrace(s)185 }186}187type AddSubContext struct {188 *ExprContext189 op antlr.Token190}191func NewAddSubContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *AddSubContext {192 var p = new(AddSubContext)193 p.ExprContext = NewEmptyExprContext()194 p.parser = parser195 p.CopyFrom(ctx.(*ExprContext))196 return p197}198func (s *AddSubContext) GetOp() antlr.Token { return s.op }199func (s *AddSubContext) SetOp(v antlr.Token) { s.op = v }200func (s *AddSubContext) GetRuleContext() antlr.RuleContext {201 return s202}203func (s *AddSubContext) AllExpr() []IExprContext {204 var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IExprContext)(nil)).Elem())205 var tst = make([]IExprContext, len(ts))206 for i, t := range ts {207 if t != nil {208 tst[i] = t.(IExprContext)209 }210 }211 return tst212}213func (s *AddSubContext) Expr(i int) IExprContext {214 var t = s.GetTypedRuleContext(reflect.TypeOf((*IExprContext)(nil)).Elem(), i)215 if t == nil {216 return nil217 }218 return t.(IExprContext)219}220func (s *AddSubContext) ADD() antlr.TerminalNode {221 return s.GetToken(MathParserADD, 0)222}223func (s *AddSubContext) SUB() antlr.TerminalNode {224 return s.GetToken(MathParserSUB, 0)225}226func (s *AddSubContext) EnterRule(listener antlr.ParseTreeListener) {227 if listenerT, ok := listener.(MathListener); ok {228 listenerT.EnterAddSub(s)229 }230}231func (s *AddSubContext) ExitRule(listener antlr.ParseTreeListener) {232 if listenerT, ok := listener.(MathListener); ok {233 listenerT.ExitAddSub(s)234 }235}236type NumContext struct {237 *ExprContext238}239func NewNumContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *NumContext {240 var p = new(NumContext)241 p.ExprContext = NewEmptyExprContext()242 p.parser = parser243 p.CopyFrom(ctx.(*ExprContext))244 return p245}246func (s *NumContext) GetRuleContext() antlr.RuleContext {247 return s248}249func (s *NumContext) ROMAN() antlr.TerminalNode {250 return s.GetToken(MathParserROMAN, 0)251}252func (s *NumContext) EnterRule(listener antlr.ParseTreeListener) {253 if listenerT, ok := listener.(MathListener); ok {254 listenerT.EnterNum(s)255 }256}257func (s *NumContext) ExitRule(listener antlr.ParseTreeListener) {258 if listenerT, ok := listener.(MathListener); ok {259 listenerT.ExitNum(s)260 }261}262type DivMulContext struct {263 *ExprContext264 op antlr.Token265}266func NewDivMulContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *DivMulContext {267 var p = new(DivMulContext)268 p.ExprContext = NewEmptyExprContext()269 p.parser = parser270 p.CopyFrom(ctx.(*ExprContext))271 return p272}273func (s *DivMulContext) GetOp() antlr.Token { return s.op }274func (s *DivMulContext) SetOp(v antlr.Token) { s.op = v }275func (s *DivMulContext) GetRuleContext() antlr.RuleContext {276 return s277}278func (s *DivMulContext) AllExpr() []IExprContext {279 var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IExprContext)(nil)).Elem())280 var tst = make([]IExprContext, len(ts))281 for i, t := range ts {282 if t != nil {283 tst[i] = t.(IExprContext)284 }285 }286 return tst287}288func (s *DivMulContext) Expr(i int) IExprContext {289 var t = s.GetTypedRuleContext(reflect.TypeOf((*IExprContext)(nil)).Elem(), i)290 if t == nil {291 return nil292 }293 return t.(IExprContext)294}295func (s *DivMulContext) DIV() antlr.TerminalNode {296 return s.GetToken(MathParserDIV, 0)297}298func (s *DivMulContext) MUL() antlr.TerminalNode {299 return s.GetToken(MathParserMUL, 0)300}301func (s *DivMulContext) EnterRule(listener antlr.ParseTreeListener) {302 if listenerT, ok := listener.(MathListener); ok {303 listenerT.EnterDivMul(s)304 }305}306func (s *DivMulContext) ExitRule(listener antlr.ParseTreeListener) {307 if listenerT, ok := listener.(MathListener); ok {308 listenerT.ExitDivMul(s)309 }310}311func (p *MathParser) Expr() (localctx IExprContext) {312 return p.expr(0)313}314func (p *MathParser) expr(_p int) (localctx IExprContext) {315 var _parentctx antlr.ParserRuleContext = p.GetParserRuleContext()316 _parentState := p.GetState()317 localctx = NewExprContext(p, p.GetParserRuleContext(), _parentState)318 var _prevctx IExprContext = localctx319 var _ antlr.ParserRuleContext = _prevctx // TODO: To prevent unused variable warning.320 _startState := 0321 p.EnterRecursionRule(localctx, 0, MathParserRULE_expr, _p)322 var _la int323 defer func() {324 p.UnrollRecursionContexts(_parentctx)325 }()326 defer func() {327 if err := recover(); err != nil {328 if v, ok := err.(antlr.RecognitionException); ok {329 localctx.SetException(v)330 p.GetErrorHandler().ReportError(p, v)331 p.GetErrorHandler().Recover(p, v)332 } else {333 panic(err)334 }335 }336 }()337 var _alt int338 p.EnterOuterAlt(localctx, 1)339 p.SetState(8)340 p.GetErrorHandler().Sync(p)341 switch p.GetTokenStream().LA(1) {342 case MathParserLPAREN:343 localctx = NewBraceContext(p, localctx)344 p.SetParserRuleContext(localctx)345 _prevctx = localctx346 {347 p.SetState(3)348 p.Match(MathParserLPAREN)349 }350 {351 p.SetState(4)352 p.expr(0)353 }354 {355 p.SetState(5)356 p.Match(MathParserRPAREN)357 }358 case MathParserROMAN:359 localctx = NewNumContext(p, localctx)360 p.SetParserRuleContext(localctx)361 _prevctx = localctx362 {363 p.SetState(7)364 p.Match(MathParserROMAN)365 }366 default:367 panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))368 }369 p.GetParserRuleContext().SetStop(p.GetTokenStream().LT(-1))370 p.SetState(21)371 p.GetErrorHandler().Sync(p)372 _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 2, p.GetParserRuleContext())373 for _alt != 2 && _alt != antlr.ATNInvalidAltNumber {374 if _alt == 1 {375 if p.GetParseListeners() != nil {376 p.TriggerExitRuleEvent()377 }378 _prevctx = localctx379 p.SetState(19)380 p.GetErrorHandler().Sync(p)381 switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 1, p.GetParserRuleContext()) {382 case 1:383 localctx = NewOrderContext(p, NewExprContext(p, _parentctx, _parentState))384 p.PushNewRecursionContext(localctx, _startState, MathParserRULE_expr)385 p.SetState(10)386 if !(p.Precpred(p.GetParserRuleContext(), 4)) {387 panic(antlr.NewFailedPredicateException(p, "p.Precpred(p.GetParserRuleContext(), 4)", ""))388 }389 {390 p.SetState(11)391 p.Match(MathParserPOW)392 }393 {394 p.SetState(12)395 p.expr(5)396 }397 case 2:398 localctx = NewDivMulContext(p, NewExprContext(p, _parentctx, _parentState))399 p.PushNewRecursionContext(localctx, _startState, MathParserRULE_expr)400 p.SetState(13)401 if !(p.Precpred(p.GetParserRuleContext(), 3)) {402 panic(antlr.NewFailedPredicateException(p, "p.Precpred(p.GetParserRuleContext(), 3)", ""))403 }404 {405 p.SetState(14)406 var _lt = p.GetTokenStream().LT(1)407 localctx.(*DivMulContext).op = _lt408 _la = p.GetTokenStream().LA(1)409 if !(_la == MathParserMUL || _la == MathParserDIV) {410 var _ri = p.GetErrorHandler().RecoverInline(p)411 localctx.(*DivMulContext).op = _ri412 } else {413 p.GetErrorHandler().ReportMatch(p)414 p.Consume()415 }416 }417 {418 p.SetState(15)419 p.expr(4)420 }421 case 3:422 localctx = NewAddSubContext(p, NewExprContext(p, _parentctx, _parentState))423 p.PushNewRecursionContext(localctx, _startState, MathParserRULE_expr)424 p.SetState(16)425 if !(p.Precpred(p.GetParserRuleContext(), 2)) {426 panic(antlr.NewFailedPredicateException(p, "p.Precpred(p.GetParserRuleContext(), 2)", ""))427 }428 {429 p.SetState(17)430 var _lt = p.GetTokenStream().LT(1)431 localctx.(*AddSubContext).op = _lt432 _la = p.GetTokenStream().LA(1)433 if !(_la == MathParserADD || _la == MathParserSUB) {434 var _ri = p.GetErrorHandler().RecoverInline(p)435 localctx.(*AddSubContext).op = _ri436 } else {437 p.GetErrorHandler().ReportMatch(p)438 p.Consume()439 }440 }441 {442 p.SetState(18)443 p.expr(3)444 }445 }446 }447 p.SetState(23)448 p.GetErrorHandler().Sync(p)449 _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 2, p.GetParserRuleContext())450 }451 return localctx452}453func (p *MathParser) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool {454 switch ruleIndex {455 case 0:456 var t *ExprContext = nil457 if localctx != nil {458 t = localctx.(*ExprContext)459 }460 return p.Expr_Sempred(t, predIndex)461 default:462 panic("No predicate with index: " + fmt.Sprint(ruleIndex))463 }464}465func (p *MathParser) Expr_Sempred(localctx antlr.RuleContext, predIndex int) bool {466 switch predIndex {467 case 0:468 return p.Precpred(p.GetParserRuleContext(), 4)469 case 1:470 return p.Precpred(p.GetParserRuleContext(), 3)471 case 2:472 return p.Precpred(p.GetParserRuleContext(), 2)473 default:474 panic("No predicate with index: " + fmt.Sprint(predIndex))475 }476}...

Full Screen

Full Screen

addon_parser.go

Source:addon_parser.go Github

copy

Full Screen

...18 "io/ioutil"19 "path/filepath"20 "regexp"21 "strings"22 "github.com/minishift/minishift/pkg/minishift/addon"23 "github.com/minishift/minishift/pkg/minishift/addon/command"24 "github.com/minishift/minishift/pkg/util/filehelper"25)26const (27 commentChar = "#"28 noAddOnDefinitionFoundError = "There needs to be an addon file per addon directory. Found none in %s"29 multipleAddOnDefinitionsError = "There can only be one addon file per addon directory. Found %s"30 multipleAddOnRemoveDefinitionsError = "There can only be one addon.remove file per addon directory. Found %s"31 regexToGetMetaTagInfo = `^# ?([a-zA-Z-]*):(.*)`32)33// AddOnParser is responsible for loading an addon from file and converting it into an AddOn34type AddOnParser struct {35 handler CommandHandler36}37func NewAddOnParser() *AddOnParser {38 parser := AddOnParser{}39 // build the responsibility chain40 ocHandler := &OcCommandHandler{&defaultCommandHandler{}}41 openshiftHandler := &OpenShiftCommandHandler{&defaultCommandHandler{}}42 ocHandler.next = openshiftHandler43 dockerHandler := &DockerCommandHandler{&defaultCommandHandler{}}44 openshiftHandler.SetNext(dockerHandler)45 sleepHandler := &SleepCommandHandler{&defaultCommandHandler{}}46 dockerHandler.SetNext(sleepHandler)47 sshHandler := &SSHCommandHandler{&defaultCommandHandler{}}48 sleepHandler.SetNext(sshHandler)49 echoHandler := &EchoCommandHandler{&defaultCommandHandler{}}50 sshHandler.SetNext(echoHandler)51 parser.handler = ocHandler52 return &parser53}54// Parse takes as parameter a reader containing an addon definition and returns an AddOn instance.55// If an error occurs, the error is returned.56func (parser *AddOnParser) Parse(addOnDir string) (addon.AddOn, error) {57 addonInstallReader, err := parser.getAddOnContentReader(addOnDir, ".addon")58 if err != nil {59 return nil, err60 }61 addonRemoveReader, err := parser.getAddOnContentReader(addOnDir, ".addon.remove")62 if err != nil {63 return nil, err64 }65 meta, commands, err := parser.parseAddOnContent(addonInstallReader)66 if err != nil {67 name := ""68 if meta != nil {69 name = meta.Name()70 }71 return nil, NewParseError(err.Error(), name, addOnDir)72 }73 var removeCommands []command.Command74 if addonRemoveReader != nil {75 _, removeCommands, err = parser.parseAddOnContent(addonRemoveReader)76 if err != nil {77 name := ""78 if meta != nil {79 name = meta.Name()80 }81 return nil, NewParseError(err.Error(), name, addOnDir)82 }83 }84 addOn := addon.NewAddOn(meta, commands, removeCommands, addOnDir)85 return addOn, nil86}87func (parser *AddOnParser) getAddOnContentReader(addOnDir string, fileSuffix string) (io.Reader, error) {88 if !filehelper.Exists(addOnDir) {89 return nil, NewParseError("Addon directory does not exist", addOnDir, "")90 }91 files, err := ioutil.ReadDir(addOnDir)92 if err != nil {93 return nil, NewParseError(fmt.Sprintf("Unexpected error reading addon content in '%s'", addOnDir), addOnDir, "")94 }95 var addOnFiles []string96 for _, fileInfo := range files {97 if strings.HasSuffix(fileInfo.Name(), fileSuffix) {98 addOnFiles = append(addOnFiles, fileInfo.Name())99 }100 }101 if fileSuffix == ".addon.remove" {102 if len(addOnFiles) == 0 {103 return nil, nil104 }105 }106 if len(addOnFiles) == 0 {107 return nil, NewParseError(fmt.Sprintf(noAddOnDefinitionFoundError, addOnDir), addOnDir, "")108 }109 if len(addOnFiles) > 1 {110 if fileSuffix == ".addon" {111 return nil, NewParseError(fmt.Sprintf(multipleAddOnDefinitionsError, strings.Join(addOnFiles, ", ")), addOnDir, "")112 }113 return nil, NewParseError(fmt.Sprintf(multipleAddOnRemoveDefinitionsError, strings.Join(addOnFiles, ", ")), addOnDir, "")114 }115 file, err := ioutil.ReadFile(filepath.Join(addOnDir, addOnFiles[0]))116 if err != nil {117 return nil, NewParseError(fmt.Sprintf("Unable to open addon definition '%s'", addOnFiles[0]), addOnDir, "")118 }119 reader := strings.NewReader(string(file))120 return bufio.NewReader(reader), nil121}122func (parser *AddOnParser) parseAddOnContent(reader io.Reader) (addon.AddOnMeta, []command.Command, error) {123 scanner := bufio.NewScanner(reader)124 meta, err := parser.parseHeader(scanner)125 if err != nil {126 return nil, nil, err127 }128 commands, err := parser.parseCommands(scanner)129 if err != nil {130 return meta, nil, err131 }132 return meta, commands, nil133}134func (parser *AddOnParser) parseHeader(scanner *bufio.Scanner) (addon.AddOnMeta, error) {135 var header []string136 var line string137 for scanner.Scan() {138 line = scanner.Text()139 if !strings.HasPrefix(line, commentChar) {140 break141 }142 header = append(header, line)143 }144 headerMeta, err := createMetaData(header)145 if err != nil {146 return nil, err147 }148 return headerMeta, nil149}150func (parser *AddOnParser) parseCommands(scanner *bufio.Scanner) ([]command.Command, error) {151 var commands []command.Command152 for scanner.Scan() {153 line := scanner.Text()154 // skip blank and comment lines155 line = strings.Trim(line, " ")156 if len(line) == 0 || strings.HasPrefix(line, commentChar) {157 continue158 }159 newCommand, err := parser.handler.Handle(parser.handler, line)160 if err != nil {161 return nil, err162 }163 commands = append(commands, newCommand)164 }165 return commands, nil166}167func createMetaData(header []string) (addon.AddOnMeta, error) {168 regex, _ := regexp.Compile(regexToGetMetaTagInfo)169 metaMap := make(map[string]interface{})170 var key string171 var value []string172 for _, line := range header {173 matches := regex.FindAllStringSubmatch(line, -1)174 if len(matches) == 0 && key == addon.DescriptionMetaTagName {175 line = strings.TrimPrefix(line, commentChar)176 metaMap[key] = append(metaMap[key].([]string), strings.TrimSpace(line))177 continue178 }179 for _, match := range matches {180 key = strings.Trim(match[1], " ")181 if key == addon.DescriptionMetaTagName {182 value = append(value, strings.Trim(match[2], " "))183 metaMap[key] = value184 continue185 }186 metaMap[key] = strings.Trim(match[2], " ")187 }188 }189 metaData, err := addon.NewAddOnMeta(metaMap)190 if err != nil {191 return nil, err192 }193 return metaData, nil194}...

Full Screen

Full Screen

claims_test.go

Source:claims_test.go Github

copy

Full Screen

1package paseto_test2import (3 "testing"4 "time"5 "aidanwoods.dev/go-paseto"6 "github.com/stretchr/testify/require"7)8func TestAllClaimsPassV2(t *testing.T) {9 token := paseto.NewToken()10 token.SetAudience("a")11 token.SetJti("b")12 token.SetIssuer("c")13 token.SetExpiration(time.Now().Add(time.Minute))14 token.SetSubject("d")15 token.SetNotBefore(time.Now().Add(25 * time.Second))16 token.SetIssuedAt(time.Now())17 key := paseto.NewV2SymmetricKey()18 secretKey := paseto.NewV2AsymmetricSecretKey()19 encrypted := token.V2Encrypt(key)20 signed := token.V2Sign(secretKey)21 parser := paseto.NewParser()22 parser.AddRule(paseto.ForAudience("a"))23 parser.AddRule(paseto.IdentifiedBy("b"))24 parser.AddRule(paseto.IssuedBy("c"))25 parser.AddRule(paseto.NotExpired())26 parser.AddRule(paseto.Subject("d"))27 parser.AddRule(paseto.ValidAt(time.Now().Add(30 * time.Second)))28 _, err := parser.ParseV2Local(key, encrypted)29 require.NoError(t, err)30 _, err = parser.ParseV2Public(secretKey.Public(), signed)31 require.NoError(t, err)32}33func TestAllClaimsPassV3(t *testing.T) {34 token := paseto.NewToken()35 token.SetAudience("a")36 token.SetJti("b")37 token.SetIssuer("c")38 token.SetExpiration(time.Now().Add(time.Minute))39 token.SetSubject("d")40 token.SetNotBefore(time.Now().Add(25 * time.Second))41 token.SetIssuedAt(time.Now())42 key := paseto.NewV3SymmetricKey()43 secretKey := paseto.NewV3AsymmetricSecretKey()44 encrypted := token.V3Encrypt(key, nil)45 signed := token.V3Sign(secretKey, nil)46 parser := paseto.NewParser()47 parser.AddRule(paseto.ForAudience("a"))48 parser.AddRule(paseto.IdentifiedBy("b"))49 parser.AddRule(paseto.IssuedBy("c"))50 parser.AddRule(paseto.NotExpired())51 parser.AddRule(paseto.Subject("d"))52 parser.AddRule(paseto.ValidAt(time.Now().Add(30 * time.Second)))53 _, err := parser.ParseV3Local(key, encrypted, nil)54 require.NoError(t, err)55 _, err = parser.ParseV3Public(secretKey.Public(), signed, nil)56 require.NoError(t, err)57}58func TestAllClaimsPassV4(t *testing.T) {59 token := paseto.NewToken()60 token.SetAudience("a")61 token.SetJti("b")62 token.SetIssuer("c")63 token.SetExpiration(time.Now().Add(time.Minute))64 token.SetSubject("d")65 token.SetNotBefore(time.Now().Add(25 * time.Second))66 token.SetIssuedAt(time.Now())67 key := paseto.NewV4SymmetricKey()68 secretKey := paseto.NewV4AsymmetricSecretKey()69 encrypted := token.V4Encrypt(key, nil)70 signed := token.V4Sign(secretKey, nil)71 parser := paseto.NewParser()72 parser.AddRule(paseto.ForAudience("a"))73 parser.AddRule(paseto.IdentifiedBy("b"))74 parser.AddRule(paseto.IssuedBy("c"))75 parser.AddRule(paseto.NotExpired())76 parser.AddRule(paseto.Subject("d"))77 parser.AddRule(paseto.ValidAt(time.Now().Add(30 * time.Second)))78 _, err := parser.ParseV4Local(key, encrypted, nil)79 require.NoError(t, err)80 _, err = parser.ParseV4Public(secretKey.Public(), signed, nil)81 require.NoError(t, err)82}83func TestFutureIat(t *testing.T) {84 token := paseto.NewToken()85 // simulated check will be 30 seconds from now86 token.SetExpiration(time.Now().Add(time.Minute))87 token.SetNotBefore(time.Now().Add(25 * time.Second))88 token.SetIssuedAt(time.Now().Add(35 * time.Second))89 key := paseto.NewV4SymmetricKey()90 encrypted := token.V4Encrypt(key, nil)91 parser := paseto.NewParser()92 parser.AddRule(paseto.ValidAt(time.Now().Add(30 * time.Second)))93 _, err := parser.ParseV4Local(key, encrypted, nil)94 require.Error(t, err)95}96func TestFutureNbf(t *testing.T) {97 token := paseto.NewToken()98 // simulated check will be 30 seconds from now99 token.SetExpiration(time.Now().Add(time.Minute))100 token.SetNotBefore(time.Now().Add(35 * time.Second))101 token.SetIssuedAt(time.Now())102 key := paseto.NewV4SymmetricKey()103 encrypted := token.V4Encrypt(key, nil)104 parser := paseto.NewParser()105 parser.AddRule(paseto.ValidAt(time.Now().Add(30 * time.Second)))106 _, err := parser.ParseV4Local(key, encrypted, nil)107 require.Error(t, err)108}109func TestFutureNbfNotBeforeNbfRule(t *testing.T) {110 token := paseto.NewToken()111 // simulated check will be 30 seconds from now112 token.SetExpiration(time.Now().Add(time.Minute))113 token.SetNotBefore(time.Now())114 token.SetIssuedAt(time.Now().Add(-2 * time.Second))115 key := paseto.NewV4SymmetricKey()116 encrypted := token.V4Encrypt(key, nil)117 parser := paseto.NewParser()118 parser.AddRule(paseto.NotBeforeNbf())119 _, err := parser.ParseV4Local(key, encrypted, nil)120 require.NoError(t, err)121}122func TestFutureNbfNotBeforeNbfRuleError(t *testing.T) {123 token := paseto.NewToken()124 // simulated check will be 30 seconds from now125 token.SetExpiration(time.Now().Add(time.Minute))126 token.SetNotBefore(time.Now().Add(35 * time.Second))127 token.SetIssuedAt(time.Now())128 key := paseto.NewV4SymmetricKey()129 encrypted := token.V4Encrypt(key, nil)130 parser := paseto.NewParser()131 parser.AddRule(paseto.NotBeforeNbf())132 _, err := parser.ParseV4Local(key, encrypted, nil)133 require.Error(t, err)134}135func TestPastExp(t *testing.T) {136 token := paseto.NewToken()137 // simulated check will be 30 seconds from now138 token.SetExpiration(time.Now().Add(29 * time.Second))139 token.SetNotBefore(time.Now().Add(25 * time.Second))140 token.SetIssuedAt(time.Now())141 key := paseto.NewV4SymmetricKey()142 encrypted := token.V4Encrypt(key, nil)143 parser := paseto.NewParser()144 parser.AddRule(paseto.ValidAt(time.Now().Add(30 * time.Second)))145 _, err := parser.ParseV4Local(key, encrypted, nil)146 require.Error(t, err)147}148func TestReadMeExample(t *testing.T) {149 token := paseto.NewToken()150 token.SetAudience("audience")151 token.SetJti("identifier")152 token.SetIssuer("issuer")153 token.SetSubject("subject")154 token.SetExpiration(time.Now().Add(time.Minute))155 token.SetNotBefore(time.Now())156 token.SetIssuedAt(time.Now())157 secretKeyHex := "b4cbfb43df4ce210727d953e4a713307fa19bb7d9f85041438d9e11b942a37741eb9dbbbbc047c03fd70604e0071f0987e16b28b757225c11f00415d0e20b1a2"158 secretKey, _ := paseto.NewV4AsymmetricSecretKeyFromHex(secretKeyHex)159 signed := token.V4Sign(secretKey, nil)160 parser := paseto.NewParser()161 parser.AddRule(paseto.ForAudience("audience"))162 parser.AddRule(paseto.IdentifiedBy("identifier"))163 parser.AddRule(paseto.IssuedBy("issuer"))164 parser.AddRule(paseto.Subject("subject"))165 parser.AddRule(paseto.NotExpired())166 parser.AddRule(paseto.ValidAt(time.Now()))167 publicKeyHex := "1eb9dbbbbc047c03fd70604e0071f0987e16b28b757225c11f00415d0e20b1a2"168 publicKey, _ := paseto.NewV4AsymmetricPublicKeyFromHex(publicKeyHex)169 parsedToken, err := parser.ParseV4Public(publicKey, signed, nil)170 require.NoError(t, err)171 require.Equal(t, token.ClaimsJSON(), parsedToken.ClaimsJSON())172}...

Full Screen

Full Screen

add

Using AI Code Generation

copy

Full Screen

1import (2type parser struct {3}4func (p *parser) add() int {5}6func main() {7 p := parser{a: 1, b: 2}8 fmt.Println("Sum of a and b is " + strconv.Itoa(p.add()))9}10p := parser{1, 2}11import (12type parser struct {13}14func (p parser) add() int {15}16func main() {17 p := parser{a: 1, b: 2}18 fmt.Println("Sum of a and b is " + strconv.Itoa(p.add()))19}20./2.go:20:9: p.add undefined (type parser has no field or method add)21import (22type parser struct {

Full Screen

Full Screen

add

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := parser{}4 p.add(1, 2)5}6import (7type parser struct {8}9func (p *parser) add(a, b int) {10 fmt.Println(a + b)11}

Full Screen

Full Screen

add

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/astaxie/beego/config"3func main() {4 config, err := config.NewConfig("ini", "conf/app.conf")5 if err != nil {6 fmt.Println(err)7 }8 fmt.Println(config.String("appname"))9 fmt.Println(config.String("httpport"))10 fmt.Println(config.String("runmode"))11}

Full Screen

Full Screen

add

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 x := parser.Parser{}4 x.Add(1, 2)5}6import (7type Parser struct {8}9func (p *Parser) Add(a, b int) int {10}11import (12func TestAdd(t *testing.T) {13 x := Parser{}14 if x.Add(1, 2) != 3 {15 t.Error("Test failed")16 }17}18import (19func BenchmarkAdd(b *testing.B) {20 x := Parser{}21 for i := 0; i < b.N; i++ {22 x.Add(1, 2)23 }24}25import (26func ExampleAdd() {27 x := Parser{}28 x.Add(1, 2)29}30import (31func BenchmarkAdd(b *testing.B) {32 x := Parser{}33 for i := 0; i < b.N; i++ {34 x.Add(1, 2)35 }36}37import (38func ExampleAdd() {39 x := Parser{}40 x.Add(1, 2)41}42import (43func BenchmarkAdd(b *testing.B) {44 x := Parser{}45 for i := 0; i < b.N; i++ {46 x.Add(1, 2)47 }48}49import (50func ExampleAdd() {51 x := Parser{}52 x.Add(1, 2)53}54import (55func BenchmarkAdd(b *testing.B) {56 x := Parser{}57 for i := 0; i < b.N; i++ {58 x.Add(1, 2)

Full Screen

Full Screen

add

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, playground")4 p := parser{}5 p.add(10,20)6}7import "fmt"8func main() {9 fmt.Println("Hello, playground")10 p := parser{}11 p.add(10,20)12}13import "fmt"14func main() {15 fmt.Println("Hello, playground")16 p := parser{}17 p.add(10,20)18}19import "fmt"20func main() {21 fmt.Println("Hello, playground")22 p := parser{}23 p.add(10,20)24}25import "fmt"26func main() {27 fmt.Println("Hello, playground")28 p := parser{}29 p.add(10,20)30}31import "fmt"32func main() {33 fmt.Println("Hello, playground")34 p := parser{}35 p.add(10,20)36}37import "fmt"38func main() {39 fmt.Println("Hello, playground")40 p := parser{}41 p.add(10,20)42}43import "fmt"44func main() {45 fmt.Println("Hello, playground")46 p := parser{}47 p.add(10,20)48}49import "fmt"50func main() {51 fmt.Println("Hello, playground")52 p := parser{}53 p.add(10,20)54}55import "fmt"56func main() {57 fmt.Println("Hello, playground")58 p := parser{}59 p.add(10,20)60}

Full Screen

Full Screen

add

Using AI Code Generation

copy

Full Screen

1var parser = flag.NewFlagSet("add", flag.ExitOnError)2parser.Parse(os.Args[2:])3args := parser.Args()4if len(args) < 2 {5 fmt.Println("Please provide 2 arguments")6}7fmt.Println(parserClass.Add(args[0], args[1]))8var parser = flag.NewFlagSet("sub", flag.ExitOnError)9parser.Parse(os.Args[2:])10args := parser.Args()11if len(args) < 2 {12 fmt.Println("Please provide 2 arguments")13}14fmt.Println(parserClass.Sub(args[0], args[1]))

Full Screen

Full Screen

add

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := parser.NewParser()4 p.Add("a", "b")5 fmt.Println(p)6}7import (8func main() {9 p := parser.NewParser()10 p.Add("a", "b")11 p.Add("c", "d")12 fmt.Println(p)13}14import (15func main() {16 p := parser.NewParser()17 p.Add("a", "b")18 p.Add("c", "d")19 p.Add("e", "f")20 fmt.Println(p)21}22import (23func main() {24 p := parser.NewParser()25 p.Add("a", "b")26 p.Add("c", "d")27 p.Add("e", "f")28 p.Add("g", "h")29 fmt.Println(p)30}31import (32func main() {33 p := parser.NewParser()34 p.Add("a", "b")35 p.Add("c", "d")36 p.Add("e", "f")37 p.Add("g", "h")38 p.Add("i", "j")39 fmt.Println(p)40}41import (42func main() {43 p := parser.NewParser()44 p.Add("a", "b")45 p.Add("c", "d")46 p.Add("e", "f")47 p.Add("g", "h")48 p.Add("i", "j")49 p.Add("k", "l")50 fmt.Println(p)51}52import (

Full Screen

Full Screen

add

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 parser := math.Parser{}5 parser.Add(2, 3)6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful