bolero
所属分类:其他
开发工具:Elixir
文件大小:0KB
下载次数:0
上传日期:2016-11-21 01:40:30
上 传 者:
sh-1993
说明: 随机数据发生器,
(random data generator,)
文件列表:
LICENSE (1065, 2016-11-20)
lib/ (0, 2016-11-20)
lib/bolero.ex (305, 2016-11-20)
lib/bolero/ (0, 2016-11-20)
lib/bolero/generators.ex (4720, 2016-11-20)
lib/bolero/modifiers.ex (1212, 2016-11-20)
lib/bolero/utils.ex (483, 2016-11-20)
mix.exs (667, 2016-11-20)
test/ (0, 2016-11-20)
test/bolero_test.exs (52, 2016-11-20)
test/generators_test.exs (5546, 2016-11-20)
test/modifiers_test.exs (450, 2016-11-20)
test/test_helper.exs (494, 2016-11-20)
# bolero
random data generator
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed as:
1. Add `bolero` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:bolero, "~> 0.1.0"}]
end
```
2. Ensure `bolero` is started before your application:
```elixir
def application do
[applications: [:bolero]]
end
```
## Usage
In this example we'll generate a URI
```elixir
use Bolero
ascii = list(char_alpha, 1, 10)
scheme =
["http", "https", "ws", "wss"]
|> pick()
host =
[ascii, ".", list(char_alpha, 1, 4)]
|> string_join()
port = int(0, 10_000)
path =
ascii
|> list(1, 5)
|> bind(&("/" <> Enum.join(&1, "/")))
query =
[ascii, "=", ascii]
|> string_join()
|> list(1, 5)
|> bind(&Enum.join(&1, "&"))
generator =
[scheme: scheme,
host: host,
port: port,
path: path,
query: oneof([query, nil])]
|> map(%URI{})
|> bind(&to_string/1)
```
We can now call `generate/1` for as many URI structs as we need:
```elixir
generator |> generate()
# "https://XBYdwIG.R:4502"
generator |> generate()
# "http://jnOIOevE.CQjX:9247/iB/bP/LVDumxzFWM?gjD=oFaKzUQuS&Ujjdpu=CvypfruKB&HazmOb=b&FEWskVjF=m&OMegDnbb=yzcKQ"
```
近期下载者:
相关文件:
收藏者: