Repository: bevyengine/bevy
File: crates/bevy_reflect/src/lib.rs (Rust)

Code before:
            b: i32,
        }

        let a2 = SNoAttr { a: 1, b: 2 };
        let b2 = SNoAttr { a: 1, b: 3 };

        let ord2 = PartialReflect::reflect_partial_cmp(&a2, &b2);
        assert_eq!(ord2, Some(Ordering::Less));
    }

    #[test]
    fn enum_variant_index_ordering() {
        use core::cmp::Ordering;

        #[derive(PartialEq, PartialOrd, Reflect, Debug)]
        enum MyEnum {
            Top,
            Center,
            Bottom,
        }

        let a = MyEnum::Top;
        let b = MyEnum::Center;
        let c = MyEnum::Bottom;

        // Variant ordering of different variant name cannot be compared.
        assert_eq!(PartialReflect::reflect_partial_cmp(&a, &b), None);
        assert_eq!(PartialReflect::reflect_partial_cmp(&b, &a), None);
        assert_eq!(PartialReflect::reflect_partial_cmp(&b, &c), None);
        assert_eq!(
            PartialReflect::reflect_partial_cmp(&a, &a),
            Some(Ordering::Equal)
        );

        #[derive(PartialEq, PartialOrd, Reflect, Debug)]
        enum MyEnum2 {
            A,
            B,
            Center,
        }
        let a1 = MyEnum2::A;
        let c1 = MyEnum2::Center;

        assert_eq!(PartialReflect::reflect_partial_cmp(&a1, &a), None);
        assert_eq!(PartialReflect::reflect_partial_cmp(&a1, &b), None);
        // Variant name same, even different type, should be comparable
        assert_eq!(
            PartialReflect::reflect_partial_cmp(&c1, &b),
            Some(Ordering::Equal)
        );
    }

Review comment (suggestion):
The test name can probably be changed since `enum_variant_index_ordering` is inaccurate with the removal of ordering by variant_index

Code after:
            b: i32,
        }

        let a2 = SNoAttr { a: 1, b: 2 };
        let b2 = SNoAttr { a: 1, b: 3 };

        let ord2 = PartialReflect::reflect_partial_cmp(&a2, &b2);
        assert_eq!(ord2, Some(Ordering::Less));
    }

    #[test]
    fn enum_variant_ordering() {
        use core::cmp::Ordering;

        #[derive(PartialEq, PartialOrd, Reflect, Debug)]
        enum MyEnum {
            Top,
            Center,
            Bottom,
        }

        let a = MyEnum::Top;
        let b = MyEnum::Center;
        let c = MyEnum::Bottom;

        // Variant ordering of different variant name cannot be compared.
        assert_eq!(PartialReflect::reflect_partial_cmp(&a, &b), None);
        assert_eq!(PartialReflect::reflect_partial_cmp(&b, &a), None);
        assert_eq!(PartialReflect::reflect_partial_cmp(&b, &c), None);
        assert_eq!(
            PartialReflect::reflect_partial_cmp(&a, &a),
            Some(Ordering::Equal)
        );

        #[derive(PartialEq, PartialOrd, Reflect, Debug)]
        enum MyEnum2 {
            A,
            B,
            Center,
        }
        let a1 = MyEnum2::A;
        let c1 = MyEnum2::Center;

        assert_eq!(PartialReflect::reflect_partial_cmp(&a1, &a), None);
        assert_eq!(PartialReflect::reflect_partial_cmp(&a1, &b), None);
        // Two enums with the same variant name across different types are currently comparable
        assert_eq!(
            PartialReflect::reflect_partial_cmp(&c1, &b),
            Some(Ordering::Equal)
        );
    }