Skip to content

Commit

Permalink
Add Persian alphabet more example in manual
Browse files Browse the repository at this point in the history
  • Loading branch information
mkutz committed Jul 11, 2024
1 parent 3da37b1 commit f26a626
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
11 changes: 9 additions & 2 deletions manual/src/docs/asciidoc/chapters/03-random.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,16 @@ include::../../../test/java/org/stubit/random/RandomDocTest.java[tag=butNot]

== Random String

The link:{javadoc-url}/random/org/stubit/random/RandomString.html[`RandomString`] and link:{javadoc-url}/random/org/stubit/random/RandomChar.html[`RandomChar`] classes allow to generate random Strings.
The link:{javadoc-url}/random/org/stubit/random/RandomString.html[`RandomString` class] allows to generate random Strings.

[source,java,indent=0]
.Random German licence plate
----
include::../../../test/java/org/stubit/random/RandomDocTest.java[tag=aStringStartingWith]
include::../../../test/java/org/stubit/random/RandomDocTest.java[tag=germanLicensePlate]
----

[source,java,indent=0]
.Random Iranian licence plate
----
include::../../../test/java/org/stubit/random/RandomDocTest.java[tag=iranianLicensePlate]
----
38 changes: 26 additions & 12 deletions manual/src/test/java/org/stubit/random/RandomDocTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import static org.stubit.random.RandomInt.aPositiveInt;
import static org.stubit.random.RandomInt.anInt;
import static org.stubit.random.RandomInt.anIntBetween;
import static org.stubit.random.RandomString.aLatinLetter;
import static org.stubit.random.RandomString.aLetterFrom;
import static org.stubit.random.RandomString.aStringStartingWith;
import static org.stubit.random.RandomString.anArabicDigit;
import static org.stubit.random.RandomString.arabicDigits;
import static org.stubit.random.RandomString.digitsFrom;
import static org.stubit.random.RandomString.latinLetters;
import static org.stubit.random.RandomString.lettersFrom;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -137,15 +140,26 @@ enum Color {
}

@Test
void randomStringStartingWith_examples() {
// tag::aStringStartingWith[]
assertThat(
aStringStartingWith(anArabicDigit())
.followedBy(aLatinLetter())
.followedBy("a")
.followedBy("-test")
.build())
.matches("\\d\\wa-test");
// end::aStringStartingWith[]
void randomString_examples() {
// tag::germanLicensePlate[]
String germanLicensePlate =
aStringStartingWith(lettersFrom(anIntBetween(1, 3), Alphabet.GERMAN).toUpperCase())
.followedBy("-")
.followedBy(latinLetters(2).toUpperCase())
.followedBy(arabicDigits(anIntBetween(1, 4)))
.build();

assertThat(germanLicensePlate).matches("[A-ZÄÖÜẞ]{1,3}-[A-Z]{2}\\d{1,4}");
// end::germanLicensePlate[]

// tag::iranianLicensePlate[]
String iranianLicensePlate =
aStringStartingWith(digitsFrom(2, DigitSystem.PERSIAN))
.followedBy(aLetterFrom(Alphabet.PERSIAN))
.followedBy(digitsFrom(3, DigitSystem.PERSIAN))
.build();

assertThat(iranianLicensePlate).matches("[۱-۹]{2}[\\u0600-\\u06FF][۱-۹]{3}");
// end::iranianLicensePlate[]
}
}
3 changes: 3 additions & 0 deletions modules/random/src/main/java/org/stubit/random/Alphabet.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class Alphabet {
'ا', 'ب', 'ج', 'د', 'ه', 'و', 'ز', 'ح', 'ط', 'ي', 'ك', 'ل', 'م', 'ن', 'س', 'ع', 'ف',
'ص', 'ق', 'ر', 'ش', 'ت', 'ث', 'خ', 'ذ', 'ض', 'ظ', 'غ'));

/** The Persian alphabet. */
public static final Alphabet PERSIAN = new Alphabet(BASIC_ARABIC, List.of('پ', 'چ', 'ژ', 'گ'));

private final List<Character> letters;

/**
Expand Down

0 comments on commit f26a626

Please sign in to comment.