Compare commits

..

No commits in common. "68f58947ac27bff395fff1b67118335e227fde80" and "8d83a9b6e88d38c1f1ea0cde00a37af1a5f1dfb0" have entirely different histories.

7 changed files with 3 additions and 263 deletions

View File

@ -33,6 +33,6 @@ s := arb.String()
```
## Documention
Online documentation, which includes examples, can be found at: http://godoc.org/sourcecode.social/reiver/go-arbitrary
Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-arbitrary
[![GoDoc](https://godoc.org/sourcecode.social/reiver/go-arbitrary?status.svg)](https://godoc.org/sourcecode.social/reiver/go-arbitrary)
[![GoDoc](https://godoc.org/github.com/reiver/go-arbitrary?status.svg)](https://godoc.org/github.com/reiver/go-arbitrary)

View File

@ -2,8 +2,6 @@ package arbitrary
import (
"math/rand"
"io/fs"
"net"
"time"
)
@ -16,21 +14,6 @@ func Bool() 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.
func Password() string {
return Default.Password()
@ -56,11 +39,6 @@ func PhoneNumber() string {
return Default.PhoneNumber()
}
// RegularFile returns an arbitrary fs.File regular-file.
func RegularFile() fs.File {
return Default.RegularFile()
}
func Runes(a ...interface{}) []rune {
return Default.Runes(a...)
}
@ -68,8 +46,3 @@ func Runes(a ...interface{}) []rune {
func String(a ...interface{}) string {
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()
}

View File

@ -1,137 +0,0 @@
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 = &regularfile
return file
}

View File

@ -1,67 +0,0 @@
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
}

View File

@ -1,27 +0,0 @@
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
}

View File

@ -4,7 +4,6 @@ import (
"io/fs"
)
// RegularFile returns an arbitrary fs.File regular-file.
func (arb T) RegularFile() fs.File {
var fns [](func()fs.File) = [](func()fs.File){

View File

@ -1,7 +1,7 @@
package arbitrary
import (
"sourcecode.social/reiver/go-strfs"
"github.com/reiver/go-strfs"
"io/fs"
"time"
@ -27,7 +27,6 @@ var (
}
)
// TextFile returns an arbitrary fs.File regular-file whose content is a text-file.
func (arb T) TextFile() fs.File {
var filecontent strfs.Content