faker_rust/default/
source.rs1use crate::base::sample;
4use crate::config::FakerConfig;
5
6pub fn git_branch() -> String {
8 let prefixes = ["feature", "bugfix", "hotfix", "release", "develop"];
9 let prefix = sample(&prefixes);
10 let config = FakerConfig::current();
11 let number = config.rand_range(1, 1000);
12 let words = ["login", "auth", "api", "ui", "fix", "update", "refactor"];
13 let word = sample(&words);
14
15 format!("{}/{}-{}", prefix, word, number)
16}
17
18pub fn git_commit_message() -> String {
20 let messages = [
21 "Fix bug in authentication",
22 "Add new feature",
23 "Update documentation",
24 "Refactor code",
25 "Fix typo",
26 "Initial commit",
27 "Merge pull request",
28 "Update dependencies",
29 ];
30 sample(&messages).to_string()
31}
32
33pub fn version() -> String {
35 let config = FakerConfig::current();
36 let major = config.rand_range(0, 10);
37 let minor = config.rand_range(0, 20);
38 let patch = config.rand_range(0, 100);
39 format!("{}.{}.{}", major, minor, patch)
40}
41
42pub fn semver() -> String {
44 version()
45}
46
47pub fn filename() -> String {
49 let names = [
50 "main", "index", "app", "config", "utils", "helpers",
51 "test", "spec", "README", "LICENSE", "package", "Cargo",
52 ];
53 let extensions = [
54 "rs", "js", "ts", "py", "rb", "java", "go", "html", "css",
55 "json", "yaml", "toml", "md", "txt",
56 ];
57 format!("{}.{}", sample(&names), sample(&extensions))
58}
59
60pub fn directory() -> String {
62 let dirs = [
63 "src", "lib", "bin", "test", "docs", "config", "assets",
64 "public", "private", "vendor", "node_modules", "target",
65 ];
66 sample(&dirs).to_string()
67}
68
69#[cfg(test)]
70mod tests {
71 use super::*;
72
73 #[test]
74 fn test_git_branch() {
75 let branch = git_branch();
76 assert!(!branch.is_empty());
77 assert!(branch.contains('/') || branch == "master" || branch == "main");
78 }
79
80 #[test]
81 fn test_git_commit_message() {
82 assert!(!git_commit_message().is_empty());
83 }
84
85 #[test]
86 fn test_version() {
87 let v = version();
88 assert!(v.contains('.'));
89 }
90
91 #[test]
92 fn test_filename() {
93 let f = filename();
94 assert!(f.contains('.'));
95 }
96
97 #[test]
98 fn test_directory() {
99 assert!(!directory().is_empty());
100 }
101}