String gets the argument at the specified index. Panics if there is no argument, or if the argument is of the wrong type. If no index is provided, String() returns a complete string representation of the arguments.
(indexOrNil ...int)
| 1083 | // If no index is provided, String() returns a complete string representation |
| 1084 | // of the arguments. |
| 1085 | func (args Arguments) String(indexOrNil ...int) string { |
| 1086 | if len(indexOrNil) == 0 { |
| 1087 | // normal String() method - return a string representation of the args |
| 1088 | var argsStr []string |
| 1089 | for _, arg := range args { |
| 1090 | argsStr = append(argsStr, fmt.Sprintf("%T", arg)) // handles nil nicely |
| 1091 | } |
| 1092 | return strings.Join(argsStr, ",") |
| 1093 | } else if len(indexOrNil) == 1 { |
| 1094 | // Index has been specified - get the argument at that index |
| 1095 | index := indexOrNil[0] |
| 1096 | var s string |
| 1097 | var ok bool |
| 1098 | if s, ok = args.Get(index).(string); !ok { |
| 1099 | panic(fmt.Sprintf("assert: arguments: String(%d) failed because object wasn't correct type: %s", index, args.Get(index))) |
| 1100 | } |
| 1101 | return s |
| 1102 | } |
| 1103 | |
| 1104 | panic(fmt.Sprintf("assert: arguments: Wrong number of arguments passed to String. Must be 0 or 1, not %d", len(indexOrNil))) |
| 1105 | } |
| 1106 | |
| 1107 | // Int gets the argument at the specified index. Panics if there is no argument, or |
| 1108 | // if the argument is of the wrong type. |