diff options
Diffstat (limited to 'tests/rustdoc-json/enums/discriminant')
7 files changed, 149 insertions, 0 deletions
diff --git a/tests/rustdoc-json/enums/discriminant/basic.rs b/tests/rustdoc-json/enums/discriminant/basic.rs new file mode 100644 index 000000000..06906df3b --- /dev/null +++ b/tests/rustdoc-json/enums/discriminant/basic.rs @@ -0,0 +1,12 @@ +#[repr(i8)] +pub enum Ordering { + // @is "$.index[*][?(@.name=='Less')].inner.discriminant.expr" '"-1"' + // @is "$.index[*][?(@.name=='Less')].inner.discriminant.value" '"-1"' + Less = -1, + // @is "$.index[*][?(@.name=='Equal')].inner.discriminant.expr" '"0"' + // @is "$.index[*][?(@.name=='Equal')].inner.discriminant.value" '"0"' + Equal = 0, + // @is "$.index[*][?(@.name=='Greater')].inner.discriminant.expr" '"1"' + // @is "$.index[*][?(@.name=='Greater')].inner.discriminant.value" '"1"' + Greater = 1, +} diff --git a/tests/rustdoc-json/enums/discriminant/expr.rs b/tests/rustdoc-json/enums/discriminant/expr.rs new file mode 100644 index 000000000..e639965e7 --- /dev/null +++ b/tests/rustdoc-json/enums/discriminant/expr.rs @@ -0,0 +1,39 @@ +pub enum Foo { + // @is "$.index[*][?(@.name=='Addition')].inner.discriminant.value" '"0"' + // @is "$.index[*][?(@.name=='Addition')].inner.discriminant.expr" '"{ _ }"' + Addition = 0 + 0, + // @is "$.index[*][?(@.name=='Bin')].inner.discriminant.value" '"1"' + // @is "$.index[*][?(@.name=='Bin')].inner.discriminant.expr" '"0b1"' + Bin = 0b1, + // @is "$.index[*][?(@.name=='Oct')].inner.discriminant.value" '"2"' + // @is "$.index[*][?(@.name=='Oct')].inner.discriminant.expr" '"0o2"' + Oct = 0o2, + // @is "$.index[*][?(@.name=='PubConst')].inner.discriminant.value" '"3"' + // @is "$.index[*][?(@.name=='PubConst')].inner.discriminant.expr" '"THREE"' + PubConst = THREE, + // @is "$.index[*][?(@.name=='Hex')].inner.discriminant.value" '"4"' + // @is "$.index[*][?(@.name=='Hex')].inner.discriminant.expr" '"0x4"' + Hex = 0x4, + // @is "$.index[*][?(@.name=='Cast')].inner.discriminant.value" '"5"' + // @is "$.index[*][?(@.name=='Cast')].inner.discriminant.expr" '"{ _ }"' + Cast = 5 as isize, + // @is "$.index[*][?(@.name=='PubCall')].inner.discriminant.value" '"6"' + // @is "$.index[*][?(@.name=='PubCall')].inner.discriminant.expr" '"{ _ }"' + PubCall = six(), + // @is "$.index[*][?(@.name=='PrivCall')].inner.discriminant.value" '"7"' + // @is "$.index[*][?(@.name=='PrivCall')].inner.discriminant.expr" '"{ _ }"' + PrivCall = seven(), + // @is "$.index[*][?(@.name=='PrivConst')].inner.discriminant.value" '"8"' + // @is "$.index[*][?(@.name=='PrivConst')].inner.discriminant.expr" '"EIGHT"' + PrivConst = EIGHT, +} + +pub const THREE: isize = 3; +const EIGHT: isize = 8; + +pub const fn six() -> isize { + 6 +} +const fn seven() -> isize { + 7 +} diff --git a/tests/rustdoc-json/enums/discriminant/limits.rs b/tests/rustdoc-json/enums/discriminant/limits.rs new file mode 100644 index 000000000..e56d5594f --- /dev/null +++ b/tests/rustdoc-json/enums/discriminant/limits.rs @@ -0,0 +1,43 @@ +// ignore-tidy-linelength +#![feature(repr128)] +#![allow(incomplete_features)] + +#[repr(u64)] +pub enum U64 { + // @is "$.index[*][?(@.name=='U64Min')].inner.discriminant.value" '"0"' + // @is "$.index[*][?(@.name=='U64Min')].inner.discriminant.expr" '"u64::MIN"' + U64Min = u64::MIN, + // @is "$.index[*][?(@.name=='U64Max')].inner.discriminant.value" '"18446744073709551615"' + // @is "$.index[*][?(@.name=='U64Max')].inner.discriminant.expr" '"u64::MAX"' + U64Max = u64::MAX, +} + +#[repr(i64)] +pub enum I64 { + // @is "$.index[*][?(@.name=='I64Min')].inner.discriminant.value" '"-9223372036854775808"' + // @is "$.index[*][?(@.name=='I64Min')].inner.discriminant.expr" '"i64::MIN"' + I64Min = i64::MIN, + // @is "$.index[*][?(@.name=='I64Max')].inner.discriminant.value" '"9223372036854775807"' + // @is "$.index[*][?(@.name=='I64Max')].inner.discriminant.expr" '"i64::MAX"' + I64Max = i64::MAX, +} + +#[repr(u128)] +pub enum U128 { + // @is "$.index[*][?(@.name=='U128Min')].inner.discriminant.value" '"0"' + // @is "$.index[*][?(@.name=='U128Min')].inner.discriminant.expr" '"u128::MIN"' + U128Min = u128::MIN, + // @is "$.index[*][?(@.name=='U128Max')].inner.discriminant.value" '"340282366920938463463374607431768211455"' + // @is "$.index[*][?(@.name=='U128Max')].inner.discriminant.expr" '"u128::MAX"' + U128Max = u128::MAX, +} + +#[repr(i128)] +pub enum I128 { + // @is "$.index[*][?(@.name=='I128Min')].inner.discriminant.value" '"-170141183460469231731687303715884105728"' + // @is "$.index[*][?(@.name=='I128Min')].inner.discriminant.expr" '"i128::MIN"' + I128Min = i128::MIN, + // @is "$.index[*][?(@.name=='I128Max')].inner.discriminant.value" '"170141183460469231731687303715884105727"' + // @is "$.index[*][?(@.name=='I128Max')].inner.discriminant.expr" '"i128::MAX"' + I128Max = i128::MAX, +} diff --git a/tests/rustdoc-json/enums/discriminant/num_underscore_and_suffix.rs b/tests/rustdoc-json/enums/discriminant/num_underscore_and_suffix.rs new file mode 100644 index 000000000..6889b305f --- /dev/null +++ b/tests/rustdoc-json/enums/discriminant/num_underscore_and_suffix.rs @@ -0,0 +1,15 @@ +#[repr(u32)] +pub enum Foo { + // @is "$.index[*][?(@.name=='Basic')].inner.discriminant.value" '"0"' + // @is "$.index[*][?(@.name=='Basic')].inner.discriminant.expr" '"0"' + Basic = 0, + // @is "$.index[*][?(@.name=='Suffix')].inner.discriminant.value" '"10"' + // @is "$.index[*][?(@.name=='Suffix')].inner.discriminant.expr" '"10u32"' + Suffix = 10u32, + // @is "$.index[*][?(@.name=='Underscore')].inner.discriminant.value" '"100"' + // @is "$.index[*][?(@.name=='Underscore')].inner.discriminant.expr" '"1_0_0"' + Underscore = 1_0_0, + // @is "$.index[*][?(@.name=='SuffixUnderscore')].inner.discriminant.value" '"1000"' + // @is "$.index[*][?(@.name=='SuffixUnderscore')].inner.discriminant.expr" '"1_0_0_0u32"' + SuffixUnderscore = 1_0_0_0u32, +} diff --git a/tests/rustdoc-json/enums/discriminant/only_some_have_discriminant.rs b/tests/rustdoc-json/enums/discriminant/only_some_have_discriminant.rs new file mode 100644 index 000000000..6a4f54de6 --- /dev/null +++ b/tests/rustdoc-json/enums/discriminant/only_some_have_discriminant.rs @@ -0,0 +1,10 @@ +pub enum Foo { + // @is "$.index[*][?(@.name=='Has')].inner.discriminant" '{"expr":"0", "value":"0"}' + Has = 0, + // @is "$.index[*][?(@.name=='Doesnt')].inner.discriminant" null + Doesnt, + // @is "$.index[*][?(@.name=='AlsoDoesnt')].inner.discriminant" null + AlsoDoesnt, + // @is "$.index[*][?(@.name=='AlsoHas')].inner.discriminant" '{"expr":"44", "value":"44"}' + AlsoHas = 44, +} diff --git a/tests/rustdoc-json/enums/discriminant/struct.rs b/tests/rustdoc-json/enums/discriminant/struct.rs new file mode 100644 index 000000000..e91a632a3 --- /dev/null +++ b/tests/rustdoc-json/enums/discriminant/struct.rs @@ -0,0 +1,15 @@ +// ignore-tidy-linelength + +#[repr(i32)] +// @is "$.index[*][?(@.name=='Foo')].attrs" '["#[repr(i32)]"]' +pub enum Foo { + // @is "$.index[*][?(@.name=='Struct')].inner.discriminant" null + // @count "$.index[*][?(@.name=='Struct')].inner.kind.struct.fields[*]" 0 + Struct {}, + // @is "$.index[*][?(@.name=='StructWithDiscr')].inner.discriminant" '{"expr": "42", "value": "42"}' + // @count "$.index[*][?(@.name=='StructWithDiscr')].inner.kind.struct.fields[*]" 1 + StructWithDiscr { x: i32 } = 42, + // @is "$.index[*][?(@.name=='StructWithHexDiscr')].inner.discriminant" '{"expr": "0x42", "value": "66"}' + // @count "$.index[*][?(@.name=='StructWithHexDiscr')].inner.kind.struct.fields[*]" 2 + StructWithHexDiscr { x: i32, y: bool } = 0x42, +} diff --git a/tests/rustdoc-json/enums/discriminant/tuple.rs b/tests/rustdoc-json/enums/discriminant/tuple.rs new file mode 100644 index 000000000..b94d5739e --- /dev/null +++ b/tests/rustdoc-json/enums/discriminant/tuple.rs @@ -0,0 +1,15 @@ +// ignore-tidy-linelength + +#[repr(u32)] +// @is "$.index[*][?(@.name=='Foo')].attrs" '["#[repr(u32)]"]' +pub enum Foo { + // @is "$.index[*][?(@.name=='Tuple')].inner.discriminant" null + // @count "$.index[*][?(@.name=='Tuple')].inner.kind.tuple[*]" 0 + Tuple(), + // @is "$.index[*][?(@.name=='TupleWithDiscr')].inner.discriminant" '{"expr": "1", "value": "1"}' + // @count "$.index[*][?(@.name=='TupleWithDiscr')].inner.kind.tuple[*]" 1 + TupleWithDiscr(i32) = 1, + // @is "$.index[*][?(@.name=='TupleWithBinDiscr')].inner.discriminant" '{"expr": "0b10", "value": "2"}' + // @count "$.index[*][?(@.name=='TupleWithBinDiscr')].inner.kind.tuple[*]" 2 + TupleWithBinDiscr(i32, i32) = 0b10, +} |