aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEric Cheng <[email protected]>2022-08-10 03:31:53 -0400
committerGitHub <[email protected]>2022-08-10 07:31:53 +0000
commit8cb6027087fbc3fd038c4063b78f283d9aa48959 (patch)
treeb4847e577e22f21ac7a92121028c6563b04a2101 /test
parentd4cfe979193c283be17016d6a1b03e745bf1511a (diff)
downloadfaker-8cb6027087fbc3fd038c4063b78f283d9aa48959.tar.xz
faker-8cb6027087fbc3fd038c4063b78f283d9aa48959.zip
feat: `datatype.hexadecimal` signature change (#1238)
Co-authored-by: Shinigami <[email protected]>
Diffstat (limited to 'test')
-rw-r--r--test/__snapshots__/datatype.spec.ts.snap30
-rw-r--r--test/datatype.spec.ts44
2 files changed, 61 insertions, 13 deletions
diff --git a/test/__snapshots__/datatype.spec.ts.snap b/test/__snapshots__/datatype.spec.ts.snap
index e7b8e414..97f2d4c6 100644
--- a/test/__snapshots__/datatype.spec.ts.snap
+++ b/test/__snapshots__/datatype.spec.ts.snap
@@ -70,9 +70,15 @@ exports[`datatype > 42 > float > with min and max 1`] = `-0.43`;
exports[`datatype > 42 > float > with min, max and precision 1`] = `-0.4261`;
-exports[`datatype > 42 > hexadecimal > noArgs 1`] = `"0x8"`;
+exports[`datatype > 42 > hexadecimal > noArgs 1`] = `"8"`;
-exports[`datatype > 42 > hexadecimal > with length 1`] = `"0x8BE4ABdd39321aD7d3fe01FfCE404F4d6db0906bd8"`;
+exports[`datatype > 42 > hexadecimal > with casing 1`] = `"8"`;
+
+exports[`datatype > 42 > hexadecimal > with length 1`] = `"8BE4ABdd39321aD7d3fe01FfCE404F4d6db0906bd8"`;
+
+exports[`datatype > 42 > hexadecimal > with length, prefix, and casing 1`] = `"0x8be4abdd39321ad7d3fe"`;
+
+exports[`datatype > 42 > hexadecimal > with prefix 1`] = `"0x8"`;
exports[`datatype > 42 > json 1`] = `"{\\"foo\\":79654,\\"bar\\":\\"2eiXX/J/*&\\",\\"bike\\":86617,\\"a\\":60111,\\"b\\":70807,\\"name\\":\\"\\\\\\"&{dnx4!1}\\",\\"prop\\":61748}"`;
@@ -180,9 +186,15 @@ exports[`datatype > 1211 > float > with min and max 1`] = `61.07`;
exports[`datatype > 1211 > float > with min, max and precision 1`] = `61.0658`;
-exports[`datatype > 1211 > hexadecimal > noArgs 1`] = `"0xE"`;
+exports[`datatype > 1211 > hexadecimal > noArgs 1`] = `"E"`;
+
+exports[`datatype > 1211 > hexadecimal > with casing 1`] = `"e"`;
+
+exports[`datatype > 1211 > hexadecimal > with length 1`] = `"EaDB42F0e3f4A973fAB0AeefCE96DFCF49cD438dF9"`;
-exports[`datatype > 1211 > hexadecimal > with length 1`] = `"0xEaDB42F0e3f4A973fAB0AeefCE96DFCF49cD438dF9"`;
+exports[`datatype > 1211 > hexadecimal > with length, prefix, and casing 1`] = `"0xeadb42f0e3f4a973fab0"`;
+
+exports[`datatype > 1211 > hexadecimal > with prefix 1`] = `"0xE"`;
exports[`datatype > 1211 > json 1`] = `"{\\"foo\\":\\"Kti5-}$_/\`\\",\\"bar\\":76408,\\"bike\\":35403,\\"a\\":69406,\\"b\\":\\"l\\\\\\"h^]dnwI<\\",\\"name\\":\\"|p|5KWu3/C\\",\\"prop\\":\\"|Jh!E=x\\\\\\"RH\\"}"`;
@@ -290,9 +302,15 @@ exports[`datatype > 1337 > float > with min and max 1`] = `-12.92`;
exports[`datatype > 1337 > float > with min, max and precision 1`] = `-12.9153`;
-exports[`datatype > 1337 > hexadecimal > noArgs 1`] = `"0x5"`;
+exports[`datatype > 1337 > hexadecimal > noArgs 1`] = `"5"`;
+
+exports[`datatype > 1337 > hexadecimal > with casing 1`] = `"5"`;
+
+exports[`datatype > 1337 > hexadecimal > with length 1`] = `"5c346ba075bd57F5A62B82d72AF39CBBB07a98cbA8"`;
+
+exports[`datatype > 1337 > hexadecimal > with length, prefix, and casing 1`] = `"0x5c346ba075bd57f5a62b"`;
-exports[`datatype > 1337 > hexadecimal > with length 1`] = `"0x5c346ba075bd57F5A62B82d72AF39CBBB07a98cbA8"`;
+exports[`datatype > 1337 > hexadecimal > with prefix 1`] = `"0x5"`;
exports[`datatype > 1337 > json 1`] = `"{\\"foo\\":56052,\\"bar\\":21258,\\"bike\\":54308,\\"a\\":3397,\\"b\\":23538,\\"name\\":\\"X9@{:e=+kD\\",\\"prop\\":62850}"`;
diff --git a/test/datatype.spec.ts b/test/datatype.spec.ts
index 56d4ea17..a57139fd 100644
--- a/test/datatype.spec.ts
+++ b/test/datatype.spec.ts
@@ -59,7 +59,15 @@ describe('datatype', () => {
t.itRepeated('boolean', 5);
t.describe('hexadecimal', (t) => {
- t.it('noArgs').it('with length', 42);
+ t.it('noArgs')
+ .it('with length', { length: 42 })
+ .it('with prefix', { prefix: '0x' })
+ .it('with casing', { case: 'lower' })
+ .it('with length, prefix, and casing', {
+ length: 20,
+ prefix: '0x',
+ case: 'lower',
+ });
});
t.it('json');
@@ -323,14 +331,36 @@ describe('datatype', () => {
describe('hexadecimal', () => {
it('generates single hex character when no additional argument was provided', () => {
const hex = faker.datatype.hexadecimal();
- expect(hex).toMatch(/^(0x)[0-9a-f]{1}$/i);
- expect(hex.substring(2)).toHaveLength(1);
+ expect(hex).toMatch(/^[0-9a-f]{1}$/i);
+ expect(hex).toHaveLength(1);
+ });
+
+ it('generates a random hex string with a provided length', () => {
+ const hex = faker.datatype.hexadecimal({ length: 5 });
+ expect(hex).toMatch(/^[0-9a-f]+$/i);
+ expect(hex).toHaveLength(5);
});
- it('generates a random hex string', () => {
- const hex = faker.datatype.hexadecimal(5);
- expect(hex).toMatch(/^(0x)[0-9a-f]+$/i);
- expect(hex.substring(2)).toHaveLength(5);
+ it('generates a hex string with a provided prefix', () => {
+ const hex = faker.datatype.hexadecimal({ prefix: '0x' });
+ expect(hex).toMatch(/^(0x)[0-9A-F]+$/i);
+ expect(hex).toHaveLength(3);
+ });
+
+ it('generates a hex string with a provided casing', () => {
+ const hex = faker.datatype.hexadecimal({ case: 'lower' });
+ expect(hex).toMatch(/^[0-9a-f]+$/i);
+ expect(hex).toHaveLength(1);
+ });
+
+ it('generates a hex string with a provided prefix, length, and casing', () => {
+ const hex = faker.datatype.hexadecimal({
+ prefix: '0x',
+ length: 7,
+ case: 'upper',
+ });
+ expect(hex).toMatch(/^(0x)[0-9A-F]+$/i);
+ expect(hex.substring(2)).toHaveLength(7);
});
});