druid-derive 0.5.1

derive impls for Druid, a Rust UI toolkit.
Documentation
// Copyright 2019 The Druid Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! testing the ignore attribute

use druid::Data;

#[test]
fn simple_ignore() {
    #[derive(Clone, Data)]
    struct Point {
        x: f64,
        #[data(ignore)]
        #[allow(dead_code)]
        y: f64,
    }
    let p1 = Point { x: 0.0, y: 1.0 };
    let p2 = Point { x: 0.0, y: 9.0 };
    assert!(p1.same(&p2));
}

#[test]
fn ignore_item_without_data_impl() {
    use std::path::PathBuf;

    #[derive(Clone, Data)]
    struct CoolStruct {
        len: usize,
        #[data(ignore)]
        #[allow(dead_code)]
        path: PathBuf,
    }
}

#[test]
fn tuple_struct() {
    #[derive(Clone, Data)]
    struct Tup(usize, #[data(ignore)] usize);

    let one = Tup(1, 1);
    let two = Tup(1, 5);
    assert!(one.same(&two));
}

#[test]
fn enums() {
    #[derive(Clone, Data)]
    enum Hmm {
        Named {
            one: usize,
            #[data(ignore)]
            two: usize,
        },
        Tuple(#[data(ignore)] usize, usize),
    }

    let name_one = Hmm::Named { one: 5, two: 4 };
    let name_two = Hmm::Named { one: 5, two: 42 };
    let tuple_one = Hmm::Tuple(2, 4);
    let tuple_two = Hmm::Tuple(9, 4);

    assert!(!name_one.same(&tuple_one));
    assert!(name_one.same(&name_two));
    assert!(tuple_one.same(&tuple_two));
}