Compare commits
10 Commits
8d83a9b6e8
...
68f58947ac
Author | SHA1 | Date |
---|---|---|
|
68f58947ac | |
|
1cb364a5b7 | |
|
651dc8481a | |
|
f58be2f83d | |
|
61ef62e23d | |
|
784b3d0ea2 | |
|
2078fe8f72 | |
|
b2733b338b | |
|
3fc35d7a32 | |
|
728a1b8a01 |
|
@ -33,6 +33,6 @@ s := arb.String()
|
||||||
```
|
```
|
||||||
## Documention
|
## Documention
|
||||||
|
|
||||||
Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-arbitrary
|
Online documentation, which includes examples, can be found at: http://godoc.org/sourcecode.social/reiver/go-arbitrary
|
||||||
|
|
||||||
[](https://godoc.org/github.com/reiver/go-arbitrary)
|
[](https://godoc.org/sourcecode.social/reiver/go-arbitrary)
|
||||||
|
|
27
default.go
27
default.go
|
@ -2,6 +2,8 @@ package arbitrary
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"io/fs"
|
||||||
|
"net"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,6 +16,21 @@ func Bool() bool {
|
||||||
return Default.Bool()
|
return Default.Bool()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTMLFile returns an arbitrary fs.File regular-file whose content is an HTML file.
|
||||||
|
func HTMLFile() fs.File {
|
||||||
|
return Default.HTMLFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
// NetAddr returns an arbitrary net.Addr.
|
||||||
|
func NetAddr() net.Addr {
|
||||||
|
return Default.NetAddr()
|
||||||
|
}
|
||||||
|
|
||||||
|
// NetPort returns an arbitrary network port.
|
||||||
|
func NetPort() uint16 {
|
||||||
|
return Default.NetPort()
|
||||||
|
}
|
||||||
|
|
||||||
// Password returns an arbitrary password.
|
// Password returns an arbitrary password.
|
||||||
func Password() string {
|
func Password() string {
|
||||||
return Default.Password()
|
return Default.Password()
|
||||||
|
@ -39,6 +56,11 @@ func PhoneNumber() string {
|
||||||
return Default.PhoneNumber()
|
return Default.PhoneNumber()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RegularFile returns an arbitrary fs.File regular-file.
|
||||||
|
func RegularFile() fs.File {
|
||||||
|
return Default.RegularFile()
|
||||||
|
}
|
||||||
|
|
||||||
func Runes(a ...interface{}) []rune {
|
func Runes(a ...interface{}) []rune {
|
||||||
return Default.Runes(a...)
|
return Default.Runes(a...)
|
||||||
}
|
}
|
||||||
|
@ -46,3 +68,8 @@ func Runes(a ...interface{}) []rune {
|
||||||
func String(a ...interface{}) string {
|
func String(a ...interface{}) string {
|
||||||
return Default.String(a...)
|
return Default.String(a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TextFile returns an arbitrary fs.File regular-file whose content is a text-file.
|
||||||
|
func TextFile() fs.File {
|
||||||
|
return Default.TextFile()
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,137 @@
|
||||||
|
package arbitrary
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sourcecode.social/reiver/go-strfs"
|
||||||
|
|
||||||
|
"io/fs"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
htmlFiles []string = []string{
|
||||||
|
"",
|
||||||
|
|
||||||
|
"Hello world!",
|
||||||
|
"Hello world!" +"\n",
|
||||||
|
"Hello world!" +"\r",
|
||||||
|
"Hello world!" +"\r\n",
|
||||||
|
"Hello world!" +"\u0085",
|
||||||
|
"Hello world!" +"\u2028",
|
||||||
|
"Hello world!" +"\u2029",
|
||||||
|
|
||||||
|
"<!DOCTYPE html>",
|
||||||
|
"<!DOCTYPE html>" +"\n",
|
||||||
|
"<!DOCTYPE html>" +"\r",
|
||||||
|
"<!DOCTYPE html>" +"\r\n",
|
||||||
|
"<!DOCTYPE html>" +"\u0085",
|
||||||
|
"<!DOCTYPE html>" +"\u2028",
|
||||||
|
"<!DOCTYPE html>" +"\u2029",
|
||||||
|
|
||||||
|
"<div></div>",
|
||||||
|
"<div></div>" +"\n",
|
||||||
|
"<div></div>" +"\r",
|
||||||
|
"<div></div>" +"\r\n",
|
||||||
|
"<div></div>" +"\u0085",
|
||||||
|
"<div></div>" +"\u2028",
|
||||||
|
"<div></div>" +"\u2029",
|
||||||
|
|
||||||
|
"<!DOCTYPE html>" +"\n" + "<html></html>",
|
||||||
|
"<!DOCTYPE html>" +"\r" + "<html></html>",
|
||||||
|
"<!DOCTYPE html>" +"\r\n" + "<html></html>",
|
||||||
|
"<!DOCTYPE html>" +"\u0085"+ "<html></html>",
|
||||||
|
"<!DOCTYPE html>" +"\u2028"+ "<html></html>",
|
||||||
|
"<!DOCTYPE html>" +"\u2029"+ "<html></html>",
|
||||||
|
|
||||||
|
"<!DOCTYPE html>" +"\n" + "<html></html>" +"\n",
|
||||||
|
"<!DOCTYPE html>" +"\r" + "<html></html>" +"\r",
|
||||||
|
"<!DOCTYPE html>" +"\r\n" + "<html></html>" +"\r\n",
|
||||||
|
"<!DOCTYPE html>" +"\u0085"+ "<html></html>" +"\u0085",
|
||||||
|
"<!DOCTYPE html>" +"\u2028"+ "<html></html>" +"\u2028",
|
||||||
|
"<!DOCTYPE html>" +"\u2029"+ "<html></html>" +"\u2029",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// HTMLFile returns an arbitrary fs.File regular-file whose content is an HTML file.
|
||||||
|
func (arb T) HTMLFile() fs.File {
|
||||||
|
|
||||||
|
var filecontent strfs.Content
|
||||||
|
{
|
||||||
|
var s string = textFiles[arb.randomness.Intn(len(textFiles))]
|
||||||
|
|
||||||
|
filecontent = strfs.CreateContent(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
var filename string
|
||||||
|
{
|
||||||
|
switch arb.randomness.Intn(10) {
|
||||||
|
case 0:
|
||||||
|
filename = "index.html"
|
||||||
|
case 1:
|
||||||
|
filename = "index.htm"
|
||||||
|
case 2:
|
||||||
|
filename = "INDEX.HTML"
|
||||||
|
case 3:
|
||||||
|
filename = "INDEX.HTM"
|
||||||
|
case 4:
|
||||||
|
filename = "about.html"
|
||||||
|
case 5:
|
||||||
|
filename = "about.htm"
|
||||||
|
case 6:
|
||||||
|
filename = "something.HoTMeTaL"
|
||||||
|
default:
|
||||||
|
filename = arb.String()
|
||||||
|
if arb.Bool() {
|
||||||
|
filename += ".html"
|
||||||
|
} else if arb.Bool() {
|
||||||
|
filename += ".htm"
|
||||||
|
} else if arb.Bool() {
|
||||||
|
filename += ".HTML"
|
||||||
|
} else if arb.Bool() {
|
||||||
|
filename += ".HTM"
|
||||||
|
} else if arb.Bool() {
|
||||||
|
filename += ".HoTMeTaL"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var filemodtime time.Time = time.Now()
|
||||||
|
func(){
|
||||||
|
if 0 == arb.randomness.Intn(10) {
|
||||||
|
filemodtime = time.Date(1970,1,1,0,0,0,0,time.UTC)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if 0 == arb.randomness.Intn(10) {
|
||||||
|
filemodtime = time.Date(1924,6,7,20,6,3,11,time.UTC)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if 0 == arb.randomness.Intn(10) {
|
||||||
|
filemodtime = time.Date(2022,12,14,20,12,23,17,time.UTC)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if 0 == 3 {
|
||||||
|
year := arb.randomness.Intn(3000)
|
||||||
|
month := time.Month(1+arb.randomness.Intn(12))
|
||||||
|
day := 1+arb.randomness.Intn(31)
|
||||||
|
hour := arb.randomness.Intn(24)
|
||||||
|
minute := arb.randomness.Intn(60)
|
||||||
|
second := arb.randomness.Intn(60)
|
||||||
|
nanosecond := arb.randomness.Intn(60)
|
||||||
|
|
||||||
|
filemodtime = time.Date(year, month, day, hour, minute, second, nanosecond, time.UTC)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
var regularfile strfs.RegularFile = strfs.RegularFile{
|
||||||
|
FileContent: filecontent,
|
||||||
|
FileName: filename,
|
||||||
|
FileModTime: filemodtime,
|
||||||
|
}
|
||||||
|
|
||||||
|
var file fs.File = ®ularfile
|
||||||
|
|
||||||
|
return file
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package arbitrary
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NetAddr returns an arbitrary net.Addr.
|
||||||
|
func (arb T) NetAddr() net.Addr {
|
||||||
|
|
||||||
|
var network string
|
||||||
|
{
|
||||||
|
if arb.Bool() {
|
||||||
|
network = "tcp"
|
||||||
|
} else {
|
||||||
|
network = "udp"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var port uint16 = arb.NetPort()
|
||||||
|
|
||||||
|
var value string
|
||||||
|
func(){
|
||||||
|
|
||||||
|
value = fmt.Sprintf("%d.%d.%d.%d:%d", arb.randomness.Intn(256), arb.randomness.Intn(256), arb.randomness.Intn(256), arb.randomness.Intn(256), port)
|
||||||
|
|
||||||
|
if 0 == arb.randomness.Intn(16) {
|
||||||
|
value = fmt.Sprintf("127.0.0.1:%d", port)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if 0 == arb.randomness.Intn(16) {
|
||||||
|
value = fmt.Sprintf("192.168.0.1:%d", port)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if 0 == arb.randomness.Intn(7) {
|
||||||
|
value = fmt.Sprintf("%d.%d:%d", arb.randomness.Intn(256), arb.randomness.Intn(16777216), port)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if 0 == arb.randomness.Intn(7) {
|
||||||
|
value = fmt.Sprintf("%d.%d.%d:%d", arb.randomness.Intn(256), arb.randomness.Intn(256), arb.randomness.Intn(65536), port)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return internalNetAddr{
|
||||||
|
network: network,
|
||||||
|
value: value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type internalNetAddr struct {
|
||||||
|
network string
|
||||||
|
value string
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ net.Addr = internalNetAddr{}
|
||||||
|
|
||||||
|
func (receiver internalNetAddr) Network() string {
|
||||||
|
return receiver.network
|
||||||
|
}
|
||||||
|
|
||||||
|
func (receiver internalNetAddr) String() string {
|
||||||
|
return receiver.value
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package arbitrary
|
||||||
|
|
||||||
|
// NetPort returns an arbitrary network port.
|
||||||
|
func (arb T) NetPort() uint16 {
|
||||||
|
|
||||||
|
var port uint16
|
||||||
|
{
|
||||||
|
port = uint16(arb.randomness.Intn(65536))
|
||||||
|
|
||||||
|
if 0 == arb.randomness.Intn(5) {
|
||||||
|
port = uint16(arb.randomness.Intn(1024))
|
||||||
|
}
|
||||||
|
|
||||||
|
if 0 == arb.randomness.Intn(4) {
|
||||||
|
port = uint16(arb.randomness.Intn(100))
|
||||||
|
}
|
||||||
|
|
||||||
|
if 0 == arb.randomness.Intn(30) {
|
||||||
|
port = 80
|
||||||
|
}
|
||||||
|
if 0 == arb.randomness.Intn(29) {
|
||||||
|
port = 79
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return port
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RegularFile returns an arbitrary fs.File regular-file.
|
||||||
func (arb T) RegularFile() fs.File {
|
func (arb T) RegularFile() fs.File {
|
||||||
|
|
||||||
var fns [](func()fs.File) = [](func()fs.File){
|
var fns [](func()fs.File) = [](func()fs.File){
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package arbitrary
|
package arbitrary
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/reiver/go-strfs"
|
"sourcecode.social/reiver/go-strfs"
|
||||||
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"time"
|
"time"
|
||||||
|
@ -27,6 +27,7 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TextFile returns an arbitrary fs.File regular-file whose content is a text-file.
|
||||||
func (arb T) TextFile() fs.File {
|
func (arb T) TextFile() fs.File {
|
||||||
|
|
||||||
var filecontent strfs.Content
|
var filecontent strfs.Content
|
||||||
|
|
Loading…
Reference in New Issue